#include <bits/stdc++.h>
using namespace std;
int n;
vector<pair<long long, int> > A;
long long dp[2005][2005];
long long nex[2005][2005];
long long ans;
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    long long a;
    cin >> a;
    A.push_back(pair<long long, int>(a, i));
  }
  sort(A.begin(), A.end(), greater<pair<long long, int> >());
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j <= i + 1; j++) {
      long long k = i - j + 1;
      if (j == 0) {
        nex[j][k] = dp[j][k - 1] + abs(n - k - A[i].second) * A[i].first;
        continue;
      }
      if (k == 0) {
        nex[j][k] = dp[j - 1][k] + abs(A[i].second - j + 1) * A[i].first;
        continue;
      }
      nex[j][k] = max(dp[j - 1][k] + abs(A[i].second - j + 1) * A[i].first,
                      dp[j][k - 1] + abs(n - k - A[i].second) * A[i].first);
    }
    swap(nex, dp);
  }
  for (int i = 0; i <= n; i++) {
    int j = n - i;
    ans = max(ans, dp[i][j]);
  }
  cout << ans << endl;
}
