#include <bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
signed main(signed argc, char **argv) {
  ios::sync_with_stdio(false), cin.tie(0);
  long long n;
  cin >> n;
  vector<long long> h(n), used(n);
  for (long long i = 0; i < n; i++) cin >> h[i];
  vector<vector<long long>> a(n + 1, vector<long long>(n + 1));
  for (long long i = 1; i <= n; i++) {
    for (long long j = 1; j <= n; j++) {
      a[i][j] = -abs(i - j) * h[i - 1];
    }
  }
  long long m = n;
  vector<long long> u(n + 1), v(m + 1), p(m + 1), way(m + 1);
  for (long long i = 1; i <= n; ++i) {
    p[0] = i;
    long long j0 = 0;
    vector<long long> minv(m + 1, (long long)(1e12));
    vector<char> used(m + 1, false);
    do {
      used[j0] = true;
      long long i0 = p[j0], delta = (long long)(1e12), j1;
      for (long long j = 1; j <= m; ++j)
        if (!used[j]) {
          long long cur = a[i0][j] - u[i0] - v[j];
          if (cur < minv[j]) minv[j] = cur, way[j] = j0;
          if (minv[j] < delta) delta = minv[j], j1 = j;
        }
      for (long long j = 0; j <= m; ++j)
        if (used[j])
          u[p[j]] += delta, v[j] -= delta;
        else
          minv[j] -= delta;
      j0 = j1;
    } while (p[j0] != 0);
    do {
      long long j1 = way[j0];
      p[j0] = p[j1];
      j0 = j1;
    } while (j0);
  }
  long long cost = v[0];
  cout << cost << '\n';
  return 0;
}
