#include <bits/stdc++.h>
using namespace std;
const int MAX = 2e5 + 111;
int n, cnt[2333], cnt1[2333];
long long a[2333];
vector<pair<long long, int> > p[2333];
int main() {
  scanf("%d", &n);
  queue<int> q;
  while (!q.empty()) q.pop();
  for (int i = 1; i <= n; i++) {
    scanf("%lld", &a[i]);
    q.push(i);
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      long long t = a[i] * abs(i - j);
      p[i].push_back({t, j});
    }
    sort(p[i].begin(), p[i].end());
  }
  long long ans = 0;
  while (!q.empty()) {
    int m = q.front();
    q.pop();
    for (int i = n - 1; i >= 0; i--) {
      long long t = p[m][i].first;
      int pos = p[m][i].second;
      if (cnt[pos]) {
        int last = cnt[pos], j = cnt1[pos];
        if (p[last][j].first < t) {
          ans += t - p[last][j].first;
          cnt[pos] = m;
          cnt1[pos] = i;
          q.push(last);
          break;
        } else if (p[last][j].first == t) {
          int k = i, l = j;
          while (p[last][j].first == p[m][k].first) j--, k--;
          if (p[last][j].first >= p[m][k].first) {
            ans += t - p[last][l].first;
            cnt[pos] = m;
            cnt1[pos] = i;
            q.push(last);
            break;
          }
        }
      } else {
        ans += t;
        cnt[pos] = m;
        cnt1[pos] = i;
        break;
      }
    }
  }
  printf("%lld\n", ans);
}
