#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e18;
const long double PI = 4 * atan((long double)1);
long long dp[2005][2005];
signed main() {
  long long n;
  cin >> n;
  vector<pair<long long, long long> > v;
  for (long long i = 1; i <= n; i++) {
    long long t;
    cin >> t;
    v.emplace_back(t, i);
  }
  sort(begin(v), end(v));
  dp[0][n + 1] = 0;
  long long ans = 0;
  for (long long i = 0; i <= n; i++) {
    for (long long l = 0; l <= i; l++) {
      long long r = n + 1 - (i - l);
      if (l < r - 1) {
        dp[l + 1][r] =
            max(dp[l + 1][r], dp[l][r] + abs(l + 1 - v[i].second) * v[i].first);
        dp[l][r - 1] =
            max(dp[l][r - 1], dp[l][r] + abs(r - 1 - v[i].second) * v[i].first);
      } else
        ans = max(ans, dp[l][r]);
    }
  }
  cout << ans;
}
