#include <bits/stdc++.h>
using namespace std;
const int N = 2009, INF = 2e9;
int n, k, w[N][N], wx[N], wy[N], d, mx[N], my[N], ans = 0;
bool vx[N], vy[N];
bool hungary(int x) {
  vx[x] = 1;
  for (int i = 1; i <= n; i++)
    if (!vy[i]) {
      if (wx[x] + wy[i] == w[x][i]) {
        vy[i] = 1;
        if (!my[i] || hungary(my[i])) {
          mx[x] = i, my[i] = x;
          return 1;
        }
      } else
        d = min(d, wx[x] + wy[i] - w[x][i]);
    }
  return 0;
}
int main() {
  fill(w[0], w[0] + N * N, -INF);
  fill(wx, wx + N, -INF);
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &k);
    for (int j = 1; j <= n; j++) wx[i] = max(wx[i], w[i][j] = abs(i - j) * k);
  }
  for (int i = 1; i <= n; i++) {
    for (;;) {
      fill(vx, vx + N, 0), fill(vy, vy + N, 0);
      d = INF;
      if (hungary(i)) break;
      for (int j = 1; j <= n; j++) wx[j] -= d * vx[j], wy[j] += d * vy[j];
    }
  }
  for (int i = 1; i <= n; i++) ans += w[i][mx[i]];
  printf("%d", ans);
  return 0;
}
