#include <bits/stdc++.h>
using namespace std;
long long n, a[2000], f1[2000], f2[2000], ans;
vector<long long> v;
int main() {
  priority_queue<pair<long long, pair<long long, long long> > > q;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      q.push({a[i] * labs(i - j) * 10000LL + labs(i - j), {i, j}});
    }
  }
  while (!q.empty()) {
    long long x, y, z;
    x = q.top().first;
    x /= 10000LL;
    y = q.top().second.first;
    z = q.top().second.second;
    if (f1[y] == 0 && f2[z] == 0) {
      f1[y] = 1;
      f2[z] = 1;
      ans += x;
    }
    q.pop();
  }
  cout << ans << endl;
}
