#include <bits/stdc++.h>
using namespace std;
int dp[2001][2001];
void printDp(int n) {
  cout << "\n";
  for (int i = 0; i < (int)n + 1; ++i) {
    for (int j = 0; j < (int)n + 1; ++j) {
      cout << dp[i][j] << " ";
    }
    cout << "\n";
  }
}
signed main(void) {
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<pair<int, int> > as = vector<pair<int, int> >();
  for (int i = 0; i < (int)n; ++i) {
    int a;
    cin >> a;
    as.push_back(pair<int, int>(a, i));
  }
  sort(as.begin(), as.end(),
       [](pair<int, int>& a, pair<int, int>& b) { return a.first > b.first; });
  for (int i = 0; i < (int)2001; ++i)
    for (int j = 0; j < (int)2001; ++j) dp[i][j] = 0;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; i + j < n; ++j) {
      pair<int, int> cur = as[i + j];
      int dis = (n - j - 1) - cur.second;
      dp[i][j + 1] =
          (((dp[i][j] + cur.first * ((dis) < 0 ? (-1 * (dis)) : (dis))) <
            (dp[i][j + 1]))
               ? (dp[i][j + 1])
               : (dp[i][j] + cur.first * ((dis) < 0 ? (-1 * (dis)) : (dis))));
      dis = i - cur.second;
      dp[i + 1][j] =
          (((dp[i][j] + cur.first * ((dis) < 0 ? (-1 * (dis)) : (dis))) <
            (dp[i + 1][j]))
               ? (dp[i + 1][j])
               : (dp[i][j] + cur.first * ((dis) < 0 ? (-1 * (dis)) : (dis))));
    }
  }
  int ans = 0;
  for (int i = 0; i <= n; ++i) {
    ans = (((ans) < (dp[i][n - i])) ? (dp[i][n - i]) : (ans));
  }
  cout << ans << "\n";
  return 0;
}
