#include <bits/stdc++.h>
using namespace std;
int dp[2020][2020];
int main() {
  int N;
  cin >> N;
  vector<pair<int, int> > A(N);
  for (int i = 0; i < (N); ++i) {
    cin >> A[i].first;
    A[i].second = i;
  }
  sort(A.begin(), A.end(), greater<pair<int, int> >());
  for (int i = 0; i < (N); ++i) {
    for (int j = 0; i + j < N; j++) {
      dp[i + 1][j] =
          max(dp[i + 1][j], dp[i][j] + A[i + j].first * (A[i + j].second - i));
      dp[i][j + 1] =
          max(dp[i][j + 1],
              dp[i][j] + A[i + j].first * (N - 1 - j - A[i + j].second));
    }
  }
  int ans = 0;
  for (int i = 0; i < (N + 1); ++i) {
    ans = max(ans, dp[i][N - i]);
  }
  cout << ans << endl;
}
