#include <bits/stdc++.h>
using namespace std;
int n;
vector<long long> a;
vector<int> to;
long long ans = 0;
long long g(int from, int to) { return a[from] * abs(from - to); }
bool f(int i, int j) {
  long long x = g(i, to[i]) + g(j, to[j]);
  long long y = g(i, to[j]) + g(j, to[i]);
  if (y > x) {
    ans += y - x;
    swap(to[i], to[j]);
    return true;
  }
  return false;
}
int main(void) {
  cin >> n;
  a.assign(n, 0);
  to.assign(n, 0);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    to[i] = i;
  }
  bool flg = true;
  while (flg) {
    flg = false;
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        if (j == i) continue;
        if (f(i, j)) flg = true;
      }
    }
  }
  cout << ans << endl;
}
