#include <bits/stdc++.h>
using namespace std;
long long int arr[2010];
long long int marked1[2010], marked2[2010];
int32_t main() {
  long long int n;
  cin >> n;
  for (long long int i = 1; i <= n; i++) {
    cin >> arr[i];
  }
  long long int ans = 0;
  priority_queue<pair<pair<long long int, long long int>,
                      pair<long long int, long long int> > >
      pq;
  for (long long int i = 1; i <= n; i++) {
    for (long long int j = 1; j <= n; j++) {
      pq.push({{arr[i] * abs(j - i), -arr[i] + abs(j - i)}, {i, j}});
    }
  }
  while (!pq.empty()) {
    pair<pair<long long int, long long int>,
         pair<long long int, long long int> >
        p = pq.top();
    pq.pop();
    long long int cur = p.first.first;
    long long int i1 = p.second.first;
    long long int i2 = p.second.second;
    if (marked1[i1] == 0 && marked2[i2] == 0) {
      ans += cur;
      marked1[i1] = 1;
      marked2[i2] = 1;
    }
  }
  cout << ans << endl;
  return 0;
}
