#include <bits/stdc++.h>
using namespace std;
using ll = long long;
void Yes(bool cnd) {
  if (cnd)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  ll ret = 0;
  int l = 0, r = n - 1;
  while (l <= r) {
    if (l != r) {
      ll ml, mr, nl = 0, nr = 0;
      for (int i = 0; i < n; i++) {
        if (a[i] != -1 && nl < a[i] * abs(l - i)) {
          ml = i;
          nl = a[i] * abs(l - i);
        }
        if (a[i] != -1 && nr < a[i] * abs(r - i)) {
          mr = i;
          nr = a[i] * abs(r - i);
        }
      }
      ll ml2, mr2, nl2 = 0, nr2 = 0;
      for (int i = 0; i < n; i++) {
        if (i == ml) continue;
        if (a[i] != -1 && nl2 < a[i] * abs(l - i)) {
          ml2 = i;
          nl2 = a[i] * abs(l - i);
        }
        if (a[i] != -1 && nr2 < a[i] * abs(r - i)) {
          mr2 = i;
          nr2 = a[i] * abs(r - i);
        }
      }
      if (ml != mr) {
        ret += a[ml] * abs(l - ml) + a[mr] * abs(r - mr);
        a[ml] = -1;
        a[mr] = -1;
      } else {
        if (a[ml2] * abs(l - ml2) + a[mr] * abs(r - mr) >
            a[ml] * abs(l - ml) + a[mr2] * abs(r - mr2)) {
          ret += a[ml2] * abs(l - ml2) + a[mr] * abs(r - mr);
          a[ml2] = -1;
          a[mr] = -1;
        } else {
          ret += a[ml] * abs(l - ml) + a[mr2] * abs(r - mr2);
          a[ml] = -1;
          a[mr2] = -1;
        }
      }
    }
    l++;
    r--;
  }
  cout << ret << endl;
}
