#include <bits/stdc++.h>
using namespace std;
const long long maxn = 2e3 + 5;
inline long long read() {
  char c = getchar();
  long long t = 0, f = 1;
  while ((!isdigit(c)) && (c != EOF)) {
    if (c == '-') f = -1;
    c = getchar();
  }
  while ((isdigit(c)) && (c != EOF)) {
    t = (t << 3) + (t << 1) + (c ^ 48);
    c = getchar();
  }
  return t * f;
}
long long n, a[maxn], vis[maxn], fd[maxn], m, b[maxn];
long long f[maxn][maxn];
bool cmp(long long x, long long y) { return a[x] > a[y]; }
signed main() {
  n = read();
  long long ans = 0;
  for (long long i = 1; i <= n; i++) {
    a[i] = read();
    b[i] = i;
  }
  sort(b + 1, b + 1 + n, cmp);
  for (long long i = 1; i <= n; i++) {
    for (long long j = 0; j <= i; j++) {
      long long k = i - j;
      if (j > 0) f[i][j] = f[i - 1][j - 1] + abs(b[i] - j) * a[b[i]];
      if (j < i)
        f[i][j] = max(f[i][j], f[i - 1][j] + abs(n - k + 1 - b[i]) * a[b[i]]);
    }
  }
  for (long long i = 1; i <= n; i++) {
    ans = max(ans, f[n][i]);
  }
  printf("%lld\n", ans);
  return 0;
}
