#include <bits/stdc++.h>
using namespace std;
int n, a[200001], v[200001], b[200001], ans;
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> a[i];
  for (int i = 1; i <= n; i++) {
    int pos, ma = 0, m;
    for (int j = 1; j <= n; j++) {
      if (b[j] == 1) continue;
      int fl, sum;
      int x = 1, y = n;
      while (v[x] == 1) x++;
      while (v[y] == 1) y--;
      if (a[j] * abs(j - x) > a[j] * abs(j - y)) {
        sum = a[j] * abs(j - x);
        fl = 0;
      } else {
        sum = a[j] * abs(j - y);
        fl = 1;
      }
      if (sum > ma) {
        m = j;
        pos = (fl == 0 ? x : y);
        ma = sum;
      }
    }
    b[m] = 1;
    v[pos] = 1;
    ans += ma;
  }
  cout << ans;
}
