#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 7;
const int MOD = 1e9 + 7;
const int dx[4] = {0, 0, -1, 1};
const int dy[4] = {-1, 1, 0, 0};
const int N = 2001;
int n;
long long dp[N][N];
pair<long long, long long> a[N];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i].first;
    a[i].second = i;
  }
  sort(a + 1, a + 1 + n);
  reverse(a + 1, a + 1 + n);
  long long res = 0;
  for (int x = 0; x <= n; x++) {
    for (int y = 0; y <= n; y++) {
      int cur = x + y;
      if (cur == n)
        res = max(res, dp[x][y]);
      else {
        cur++;
        dp[x + 1][y] =
            max(dp[x + 1][y],
                dp[x][y] + abs(a[cur].second - (x + 1)) * a[cur].first);
        dp[x][y + 1] =
            max(dp[x][y + 1],
                dp[x][y] + abs(a[cur].second - (n - y)) * a[cur].first);
        if (x == 0 && y == 0) {
        }
      }
    }
  }
  cout << res;
  return 0;
}
