#include <bits/stdc++.h>
using namespace std;
int N;
int main() {
  cin >> N;
  vector<unsigned long long> A(N);
  vector<int> id(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    id[i] = i;
  }
  while (1) {
    int www = 0;
    for (int i = 0; i < N; i++) {
      for (int j = i; j < N; j++) {
        if (A[i] * (unsigned long long)abs(id[i] - i) +
                A[j] * (unsigned long long)abs(id[j] - j) <
            A[i] * (unsigned long long)abs(id[j] - i) +
                A[j] * (unsigned long long)abs(id[i] - j)) {
          int k = id[i];
          id[i] = id[j];
          id[j] = k;
          www = 1;
        }
      }
    }
    if (www == 0) break;
  }
  unsigned long long ans = 0;
  for (int i = 0; i < N; i++) {
    ans += A[i] * (unsigned long long)abs(id[i] - i);
  }
  cout << ans << endl;
  return 0;
}
