#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2010;
const int MAXA = 1e9;
pair<int, int> A[MAXN];
int f[MAXN][MAXN];
int N;
int ans;
int main() {
  cin >> N;
  memset(f, 0, sizeof(f));
  for (int i = 1; i <= N; i++) {
    cin >> A[i].first;
    A[i].second = i;
  }
  sort(A + 1, A + N + 1);
  ans = 0;
  for (int len = N; len >= 1; len--) {
    for (int i = 1; i + len - 1 <= N; i++) {
      int j = i + len - 1;
      if (len == 1) {
        ans = max(ans, f[i][i] + A[len].first * abs(A[len].second - i));
      }
      f[i + 1][j] =
          max(f[i + 1][j], f[i][j] + A[len].first * abs(A[len].second - i));
      f[i][j - 1] =
          max(f[i][j - 1], f[i][j] + A[len].first * abs(A[len].second - j));
    }
  }
  cout << ans << endl;
  return 0;
}
