#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1e18;
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
int main() {
  int N;
  cin >> N;
  vector<pair<int, int>> A(2010);
  int tmp;
  for (int i = 0; i < (N); ++i) {
    cin >> tmp;
    A[i] = make_pair(tmp, i);
  }
  sort(A.begin(), A.end(), greater<pair<int, int>>());
  vector<vector<int>> dp(2010, vector<int>(2010, 0));
  int ans = 0;
  for (int l = 0; l < (N); ++l) {
    for (int r = 0; r < (N); ++r) {
      if (l + r == N) {
        chmax(ans, dp[l][r]);
        break;
      } else {
        chmax(dp[l + 1][r], dp[l][r] + A[l + r].first * (A[l + r].second - l));
        chmax(dp[l][r + 1],
              dp[l][r] + A[l + r].first * ((N - 1 - r) - A[l + r].second));
      }
    }
  }
  cout << ans << endl;
  return 0;
}
