#include <bits/stdc++.h>
using namespace std;
char buf[1 << 15], *fs, *ft;
inline char getc() {
  return (fs == ft &&
          (ft = (fs = buf) + fread(buf, 1, 1 << 15, stdin), fs == ft))
             ? 0
             : *fs++;
}
inline long long read() {
  register long long x = 0, f = 1;
  register char ch = getc();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getc();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getc();
  }
  return x * f;
}
const long long MAXN = 2010;
long long n, ans;
long long f[MAXN][MAXN];
struct wy {
  long long x, id;
} t[MAXN];
inline long long cmp(wy a, wy b) { return a.x > b.x; }
signed main() {
  n = read();
  for (register long long i = 1; i <= n; ++i) t[i] = (wy){read(), i};
  sort(t + 1, t + 1 + n, cmp);
  for (register long long i = 1; i <= n; ++i) {
    for (register long long j = 1; j <= i; ++j) {
      if (j <= i - 1)
        f[i][j] = max(f[i][j],
                      f[i - 1][j] + abs(t[i].id - (n - (i - 1 - j))) * t[i].x);
      f[i][j] = max(f[i][j], f[i - 1][j - 1] + abs(t[i].id - j) * t[i].x);
    }
  }
  for (register long long i = 1; i <= n; ++i) ans = max(ans, f[n][i]);
  printf("%lld\n", ans);
  return 0;
}
