#include <bits/stdc++.h>
using namespace std;
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
const long long MOD = 1e9 + 7;
const long long INF = 1e18;
const int MAX = 510000;
const double pi = acos(-1);
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
long long dp[2010][2010];
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<pair<long long, long long> > vec(n);
  for (long long i = 0; i < (long long)(n); i++) {
    long long x;
    cin >> x;
    vec[i] = pair<long long, long long>(x, i);
  }
  sort(vec.begin(), vec.end(), greater<pair<long long, long long> >());
  long long ans = 0;
  for (long long l = 0; l < (long long)(n); l++) {
    for (long long r = 0; r < (long long)(n); r++) {
      if (l + r == n) {
        chmax(ans, dp[l][r]);
        break;
      } else {
        chmax(dp[l + 1][r],
              dp[l][r] + vec[l + r].first * (abs(l - vec[l + r].second)));
        chmax(
            dp[l][r + 1],
            dp[l][r] + vec[l + r].first * (abs(n - 1 - r - vec[l + r].second)));
      }
    }
  }
  cout << ans << endl;
}
