#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<pair<long, long>> A(N);
  vector<vector<long>> DP(N, vector<long>(N));
  for (int i = (int)(0); i < (int)(N); i++) {
    int a;
    cin >> a;
    A[i] = {a, i + 1};
  }
  sort(A.rbegin(), A.rend());
  DP[1][0] = A[0].first * (N - A[0].second);
  DP[0][1] = A[0].first * (A[0].second - 1);
  for (int i = (int)(2); i < (int)(N); i++) {
    for (int j = (int)(0); j < (int)(i + 1); j++) {
      if (j == 0) {
        DP[i][0] =
            DP[i - 1][0] + A[i - 1].first * (N + 1 - i - A[i - 1].second);
        continue;
      }
      if (j == i) {
        DP[0][i] = DP[0][i - 1] + A[i - 1].first * (A[i - 1].second - i);
        continue;
      }
      DP[i - j][j] =
          max(DP[i - 1 - j][j] +
                  A[i - 1].first * (N + 1 - (i - j) - A[i - 1].second),
              DP[i - j][j - 1] + A[i - 1].first * (A[i - 1].second - j));
    }
  }
  long ans = 0;
  for (int i = (int)(0); i < (int)(N); i++) ans = max(ans, DP[N - 1 - i][i]);
  cout << ans << endl;
}
