#include <bits/stdc++.h>
using namespace std;
const int N = 2001;
int n;
long long dp[N][N];
vector<pair<int, int>> a;
void solve() {
  cin >> n;
  a.assign(n, {0, 0});
  for (int i = 0; i < n; ++i) {
    cin >> a[i].first;
    a[i].second = i;
  }
  sort(a.rbegin(), a.rend());
  long long ans = 0;
  for (int l = 0; l < n; ++l) {
    for (int r = n - 1; r >= 0; --r) {
      int idx = l + n - 1 - r;
      if (l <= r) {
        if (l + 1 < n) {
          dp[l + 1][r] = max(dp[l + 1][r],
                             dp[l][r] + a[idx].first * abs(l - a[idx].second));
          ans = max(ans, dp[l + 1][r]);
        }
        if (r - 1 > 0) {
          dp[l][r - 1] = max(dp[l][r - 1],
                             dp[l][r] + a[idx].first * abs(r - a[idx].second));
          ans = max(ans, dp[l][r - 1]);
        }
      }
      ans = max(ans, dp[l][r]);
    }
  }
  cout << ans << endl;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  while (t--) solve();
  return 0;
}
