#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
const int INF = 1000000000;
const int MAX = 2005;
int dp[MAX][MAX];
int main() {
  cin.tie(0);
  ios::sync_with_stdio(0);
  int N;
  cin >> N;
  vector<pair<int, int>> Apos;
  for (int i = 0; i < (N); ++i) {
    int A;
    cin >> A;
    Apos.push_back({A, i});
  }
  sort(Apos.rbegin(), Apos.rend());
  for (int i = 0; i < (N); ++i)
    for (int j = 0; j < (N); ++j) dp[i][j] = -INF;
  dp[0][0] = 0;
  for (int i = 0; i < (N); ++i) {
    int c = Apos[i].first;
    int p = Apos[i].second;
    for (int j = 0; j < (i + 2); ++j) {
      int il = j - 1;
      int ir = N - i + j - 1;
      if (j == 0) {
        dp[i + 1][0] = dp[i][0] + c * (ir - p);
      } else {
        dp[i + 1][j] =
            max(dp[i][j] + c * (ir - p), dp[i][j - 1] + c * (p - il));
      }
    }
  }
  int ans = dp[N][0];
  for (int i = 0; i < (N); ++i) {
    ans = max(ans, dp[N][i]);
  }
  cout << ans << endl;
  return 0;
}
