#include <bits/stdc++.h>
using namespace std;
struct kid {
  int index;
  int value;
};
bool operator<(struct kid a, struct kid b) { return a.value < b.value; }
long long int ans;
long long int dp[2001][2001];
int main() {
  int N;
  priority_queue<struct kid> queue;
  struct kid A[2000];
  cin >> N;
  for (int i = 0; i < N; i++) {
    A[i].index = i;
    cin >> A[i].value;
    queue.push(A[i]);
  }
  for (int i = 0; i <= N; i++)
    for (int j = 0; j <= N; j++) dp[i][j] = 0;
  int i = 1;
  while (!queue.empty()) {
    struct kid kid = queue.top();
    for (int j = 0; j <= i; j++) {
      long long int a = 0, b = 0;
      if (i - j > 0) {
        a = dp[j][i - j - 1] + kid.value * max(kid.index - (N - (i - j)),
                                               (N - (i - j)) - kid.index);
      }
      if (j > 0) {
        b = dp[j - 1][i - j] +
            kid.value * max(kid.index - (j - 1), (j - 1) - kid.index);
      }
      dp[j][i - j] = max(a, b);
      ans = max(dp[j][i - j], ans);
    }
    i++;
    queue.pop();
  }
  cout << ans << endl;
  return 0;
}
