#include <bits/stdc++.h>
static const int MAX = 3000;
using namespace std;
int main() {
  int n;
  cin >> n;
  int dp[MAX][MAX];
  vector<pair<int, int> > A;
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    A.push_back(make_pair(i, a));
  }
  sort(A.begin(), A.end());
  int m = 0;
  for (int i = 0; i <= n; i++)
    for (int j = 0; j <= n; j++) dp[i][j] = 0;
  for (int l = 0; l <= n; l++) {
    for (int r = 0; r <= n; r++) {
      if (l + r == n) {
        m = max(m, dp[l][r]);
        break;
      }
      int act = A[l + r].second, idx = A[l + r].first;
      dp[l + 1][r] = max(dp[l + 1][r], dp[l][r] + act * abs(l - idx));
      dp[l][r + 1] = max(dp[l][r + 1], dp[l][r] + act * abs(n - 1 - r - idx));
    }
  }
  cout << m << endl;
  return 0;
}
