#include <bits/stdc++.h>
using namespace std;
long long f[2010][2010], p[2010], a[2010], ji[2010];
struct Node {
  long long v, p;
} b[2010];
bool cmp(const Node &t1, const Node &t2) { return t1.v > t2.v; }
int main() {
  int n, m = 1;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    int x;
    scanf("%d", &x);
    b[i].v = x;
    b[i].p = i;
  }
  sort(b + 1, b + n + 1, cmp);
  f[1][n] = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j <= i; j++) {
      int l = j + 1;
      int r = n - i + j;
      if (r + 1 <= n)
        f[l][r] = max(f[l][r], f[l][r + 1] + b[i].v * abs(r + 1 - b[i].p));
      if (l - 1 >= 1)
        f[l][r] = max(f[l][r], f[l - 1][r] + b[i].v * abs(l - 1 - b[i].p));
    }
  }
  long long ans = 0;
  for (int i = 1; i <= n; i++) ans = max(ans, f[i][i - 1]);
  printf("%lld\n", ans);
  return 0;
}
