#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, a[2009], sm = 0;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  int left = 0, right = n - 1;
  while (left <= right) {
    int il, ir;
    long long mxl = 0, mxr = 0;
    for (int i = 0; i < n; i++) {
      if ((mxl < abs(i - left) * a[i]) ||
          (mxl == abs(i - left) * a[i] && a[i] > a[il])) {
        mxl = abs(i - left) * a[i];
        il = i;
      }
    }
    for (int i = n - 1; i >= 0; i--) {
      if ((mxr < abs(i - right) * a[i]) ||
          (mxl == abs(i - right) * a[i] && a[i] > a[ir])) {
        mxr = abs(i - right) * a[i];
        ir = i;
      }
    }
    if (mxl > mxr) {
      sm += mxl;
      a[il] = 0;
      left++;
    } else {
      sm += mxr;
      a[ir] = 0;
      right--;
    }
  }
  cout << sm << endl;
}
