#include <bits/stdc++.h>
using namespace std;
using P = pair<long long, long long>;
using V = vector<long long>;
bool pre[2001];
void solve_abc_e() {
  long long n;
  long long ans = 0;
  cin >> n;
  V a(n);
  priority_queue<P> pq;
  for (long long i = 0; i < (long long)(n); i++) {
    cin >> a[i];
    pq.push(make_pair(max(a[i] * i, a[i] * (n - i - 1)), i));
  }
  long long dir1, dir2;
  long long val, idx, bv, bi;
  while (pq.size() > 0) {
    idx = pq.top().second;
    val = a[idx];
    bv = 0;
    bi = -1;
    for (long long i = 0; i < (long long)(n); i++) {
      if (!pre[i]) {
        dir1 = idx - i;
      } else {
        dir1 = -1;
      }
      if (!pre[n - 1 - i]) {
        dir2 = n - 1 - i - idx;
      } else {
        dir2 = -1;
      }
      if (dir1 > 0 || dir2 > 0) {
        if (dir1 > dir2) {
          if (bv < val * dir1) {
            bv = val * dir1;
            bi = i;
          }
        } else {
          if (bv < val * dir2) {
            bv = val * dir2;
            bi = n - 1 - i;
          }
        }
      }
    }
    ans += bv;
    pre[bi] = true;
    pq.pop();
  }
  cout << ans << "\n";
}
int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  solve_abc_e();
  return 0;
}
