#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e18;
long long dp[2010][2010];
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  pair<int, int> ary[n];
  for (int i = (int)(0); i < (int)(n); ++i) {
    int tmpa;
    cin >> tmpa;
    ary[i] = make_pair(tmpa, i);
  }
  sort(ary, ary + n, greater<pair<int, int> >());
  for (int i = (int)(0); i < (int)(n + 1); ++i)
    for (int j = (int)(0); j < (int)(n + 1); ++j) dp[i][j] = 0;
  for (int i = (int)(1); i < (int)(n + 1); ++i) {
    for (int j = (int)(0); j < (int)(i + 1); ++j) {
      int l = j;
      int r = i - l;
      if (l == 0) {
        dp[l][r] =
            max(dp[l][r], dp[l][r - 1] + abs((n - r) - ary[i - 1].second) *
                                             ary[i - 1].first);
      } else if (r == 0) {
        dp[l][r] =
            max(dp[l][r], dp[l - 1][r] + abs((l - 1) - ary[i - 1].second) *
                                             ary[i - 1].first);
      } else {
        dp[l][r] =
            max(dp[l][r], dp[l - 1][r] + abs((l - 1) - ary[i - 1].second) *
                                             ary[i - 1].first);
        dp[l][r] =
            max(dp[l][r], dp[l][r - 1] + abs((n - r) - ary[i - 1].second) *
                                             ary[i - 1].first);
      }
    }
  }
  long long ans = 0;
  for (int i = (int)(0); i < (int)(n + 1); ++i) {
    ans = max(ans, dp[i][n - i]);
  }
  cout << ans << endl;
}
