#include <bits/stdc++.h>
using namespace std;
const int BIG_NUM = 1e9;
const long long INF = 1000000000000000000;
const long long MOD = 998244353;
int main() {
  int n;
  cin >> n;
  vector<pair<long long, long long> > a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i].first;
    a[i].second = i;
  }
  long long sum = 0;
  for (int i = 0; i < n; i++) {
    long long sw = 0;
    pair<int, int> p;
    for (int j = 0; j < n; j++) {
      long long s = a[i].first * (abs(j - a[i].second) - abs(i - a[i].second));
      s += a[j].first * (abs(i - a[j].second) - abs(j - a[j].second));
      if (s > sw) {
        sw = s;
        p = make_pair(i, j);
      }
    }
    if (sw > 0) {
      swap(a[p.first], a[p.second]);
      sum += sw;
    }
  }
  cout << sum << endl;
}
