#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, ma, pos, resp = 0, e = 0, d;
  cin >> n;
  vector<int> v(n);
  d = n - 1;
  for (int i = 0; i < n; i++) cin >> v[i];
  for (int i = 0; i < n; i++) {
    ma = 0;
    for (int j = 0; j < n; j++) {
      if (ma < max(abs(j - e), abs(j - d)) * v[j]) {
        ma = max(abs(j - e), abs(j - d)) * v[j];
        pos = j;
      }
    }
    resp += ma;
    if (abs(pos - e) > abs(pos - d)) {
      e++;
    } else
      d--;
    v[pos] = -1;
  }
  cout << resp << endl;
  return 0;
}
