#include <bits/stdc++.h>
using namespace std;
long long dp[2001][2001];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  cin >> n;
  vector<pair<long long, long long> > in(n);
  int i;
  for (i = 0; i < n; i++) {
    cin >> in[i].first;
    in[i].second = i;
  }
  sort(in.begin(), in.end());
  long long ans(0);
  long long cnt(0);
  memset(dp, 0, sizeof(dp));
  for (int i = n - 1; i >= 0; i--) {
    long long val = in[i].first;
    long long pos = in[i].second;
    cnt++;
    long long cc = n - cnt;
    for (long long j = 0; j < cnt + 1; j++) {
      long long left = j;
      long long right = j + cc;
      long long t = 0;
      if (left > 0) {
        t = max(t, dp[left - 1][right] + val * abs(left - 1 - pos));
      }
      if (right < n) {
        t = max(t, dp[left][right + 1] + val * abs(right - pos));
      }
      dp[left][right] = t;
    }
  }
  for (i = 0; i < n; i++) {
    ans = max(ans, dp[i][i]);
  }
  cout << ans << endl;
}
