#include <bits/stdc++.h>
using namespace std;
inline int read() {
  char ch = getchar();
  int ret = 0, f = 1;
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  for (; ch >= '0' && ch <= '9'; ch = getchar()) ret = ret * 10 + ch - '0';
  return ret * f;
}
const int INF = 1 << 30;
const int maxn = 2000 + 10;
int num[maxn], id[maxn];
int cmp(int a, int b) { return num[a] > num[b]; }
long long dp[maxn][maxn];
int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; ++i) cin >> num[i];
  for (int i = 1; i <= n; ++i) id[i] = i;
  sort(id + 1, id + n + 1, cmp);
  memset(dp, -2, sizeof dp);
  dp[0][0] = 0;
  long long ans = 0;
  for (int i = 1; i <= n; ++i) {
    for (int j = 0; j <= i; ++j) {
      if (j > 0)
        dp[i][j] =
            max(dp[i][j], dp[i - 1][j - 1] + num[id[i]] * abs(id[i] - j));
      if (i - j > 0)
        dp[i][j] =
            max(dp[i][j],
                dp[i - 1][j] + num[id[i]] * abs(id[i] - (n - (i - j) + 1)));
      if (i == n) ans = max(ans, dp[i][j]);
    }
  }
  cout << ans << endl;
  return 0;
}
