#include <bits/stdc++.h>
using namespace std;
long long N;
long long A[2000];
long long P[2000];
long long dfs(long long l, long long r) {
  if (l - r == 1) return 0;
  long long mx = 0, mxi = 0;
  for (long long i = 0; i < N; i++) {
    if (P[i] != -1) continue;
    long long d = max(abs(i - l), abs(r - i));
    long long da = d * A[i];
    if (mx < da) {
      mx = da;
      mxi = i;
    }
  }
  P[mxi] = 1;
  if (abs(mxi - l) == abs(r - mxi)) {
    long long ll = dfs(l + 1, r);
    long long rr = dfs(l, r - 1);
    P[mxi] = -1;
    return max(ll, rr) + mx;
  }
  if (abs(mxi - l) > abs(r - mxi)) {
    long long a = dfs(l + 1, r);
    P[mxi] = -1;
    return a + mx;
  } else {
    long long a = dfs(l, r - 1);
    P[mxi] = -1;
    return a + mx;
  }
}
signed main() {
  cin >> N;
  for (long long i = 0; i < N; i++) cin >> A[i];
  fill(P, P + N, -1);
  cout << dfs(0, N - 1) << endl;
}
