#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];
bool cmp(long long x, long long y) { return a[x] < a[y]; }
bool cmp2(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();
  for (long long i = 1; i <= n; i++) {
    long long tot = 0, len = n - i;
    m = i;
    for (long long j = 1; j <= i; j++) {
      b[j] = j;
    }
    sort(b + 1, b + 1 + m, cmp);
    for (long long j = 1; j <= m; j++) {
      tot = tot + a[b[j]] * (j + len - b[j]);
    }
    m = 0;
    for (long long j = i + 1; j <= n; j++) {
      b[++m] = j;
    }
    sort(b + 1, b + 1 + m, cmp2);
    for (long long j = 1; j <= m; j++) {
      tot = tot + a[b[j]] * (b[j] - j);
    }
    ans = max(ans, tot);
  }
  printf("%lld\n", ans);
  return 0;
}
