#include <bits/stdc++.h>
using namespace std;
const int N = 2000 + 10;
struct node {
  int k, p;
} a[N];
int n, f[N][N], ans;
bool cmp(node x, node y) { return x.k > y.k; }
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i].k);
    a[i].p = i;
  }
  sort(a + 1, a + n + 1, cmp);
  for (int i = 0; i <= n; i++) {
    for (int j = 0; j <= n - i + 1; j++) {
      f[i + 1][j] = max(f[i + 1][j], f[i][j] + abs(a[i + j + 1].p - (i + 1)) *
                                                   a[i + j + 1].k);
      f[i][j + 1] =
          max(f[i][j + 1], f[i][j] + abs(a[i + j + 1].p - (n - (j + 1) + 1)) *
                                         a[i + j + 1].k);
    }
  }
  for (int i = 0; i <= n; i++) ans = max(ans, f[i][n - i]);
  printf("%d\n", ans);
  return 0;
}
