#include <bits/stdc++.h>
using namespace std;
long long n, ans;
bool f[2000], F[2000];
priority_queue<pair<long long, long long>> pq[2000];
signed main() {
  cin >> n;
  for (long long i = 0; i < (long long)(n); ++i) {
    long long a;
    cin >> a;
    for (long long j = 0; j < (long long)(n); ++j)
      pq[i].push(make_pair(a * abs(i - j), j));
  }
  for (long long i = 0; i < (long long)(n); ++i) {
    long long idx, now = 0;
    pair<long long, long long> m;
    for (long long j = 0; j < (long long)(n - 1); ++j) {
      if (!F[j]) {
        while (f[pq[j].top().second]) pq[j].pop();
        auto fir = pq[j].top();
        pq[j].pop();
        while (f[pq[j].top().second]) pq[j].pop();
        auto sec = pq[j].top();
        pq[j].push(fir);
        if (now < fir.first) {
          now = fir.first;
          idx = j;
          m = fir;
        }
      }
    }
    ans += m.first;
    f[m.second] = true;
    F[idx] = true;
  }
  for (long long i = 0; i < (long long)(n); ++i)
    if (!F[i]) {
      while (f[pq[i].top().second]) pq[i].pop();
      ans += pq[i].top().first;
    }
  cout << ans << endl;
}
