#include <bits/stdc++.h>
using namespace std;
void Ans(bool x) {
  if (x)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}
const long long int INF = 1001001001;
const long long int mod = 10000000007;
int p(int i, int j) {
  if (i >= j) {
    return i - j;
  } else {
    return j - i;
  }
}
int main() {
  int n;
  cin >> n;
  pair<int, int> v[n];
  int a;
  for (int i = 0; i < (int)(n); i++) {
    cin >> a;
    v[i] = pair<int, int>(a, i);
  }
  int ans = 0;
  for (int i = 0; i < (int)(n); i++) {
    int q, w;
    q = 0;
    for (int j = 0; j < (int)(n); j++) {
      int now = 0;
      now += v[i].first * p(j, v[i].second);
      now -= v[i].first * p(i, v[i].second);
      now += v[j].first * p(i, v[j].second);
      now -= v[j].first * p(j, v[j].second);
      if (q < now) {
        q = now;
        w = j;
      }
    }
    if (q > 0) {
      pair<int, int> e = v[i];
      v[i] = v[w];
      v[w] = e;
      ans += q;
    }
  }
  cout << ans << endl;
}
