#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2000;
inline long long read() {
  long long x = 0;
  char c = getchar();
  while (c < '0' || c > '9') c = getchar();
  while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
  return x;
}
long long n, k, t, aa[MAXN + 10][MAXN + 10];
struct hh {
  long long x;
  int y;
} a[MAXN + 10];
int cmp(hh a, hh y) { return a.x > y.x; }
long long run(int l, int r) {
  if (l > r) return 0;
  if (aa[l][r]) return aa[l][r];
  int i = n - (r - l);
  return aa[l][r] = max(run(l, r - 1) + a[i].x * (r - a[i].y),
                        run(l + 1, r) + a[i].x * (a[i].y - l));
}
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    a[i].x = read();
    a[i].y = i;
  }
  sort(a + 1, a + n, cmp);
  run(1, n);
  cout << aa[1][n] << endl;
}
