#include <bits/stdc++.h>
int n, nx, ny;
int link[2010], lx[2010], ly[2010], slack[2010];
int visx[2010], visy[2010], w[2010][2010];
int DFS(int x) {
  visx[x] = 1;
  for (int y = 1; y <= ny; y++) {
    if (visy[y]) continue;
    int t = lx[x] + ly[y] - w[x][y];
    if (t == 0) {
      visy[y] = 1;
      if (link[y] == -1 || DFS(link[y])) {
        link[y] = x;
        return 1;
      }
    } else if (slack[y] > t)
      slack[y] = t;
  }
  return 0;
}
int KM() {
  int i, j;
  memset(link, -1, sizeof(link));
  memset(ly, 0, sizeof(ly));
  for (i = 1; i <= nx; i++)
    for (j = 1, lx[i] = -0x3f3f3f3f; j <= ny; j++)
      if (w[i][j] > lx[i]) lx[i] = w[i][j];
  for (int x = 1; x <= nx; x++) {
    for (i = 1; i <= ny; i++) slack[i] = 0x3f3f3f3f;
    while (1) {
      memset(visx, 0, sizeof(visx));
      memset(visy, 0, sizeof(visy));
      if (DFS(x)) break;
      int d = 0x3f3f3f3f;
      for (i = 1; i <= ny; i++)
        if (!visy[i] && d > slack[i]) d = slack[i];
      for (i = 1; i <= nx; i++)
        if (visx[i]) lx[i] -= d;
      for (i = 1; i <= ny; i++)
        if (visy[i])
          ly[i] += d;
        else
          slack[i] -= d;
    }
  }
  int res = 0;
  for (i = 1; i <= ny; i++)
    if (link[i] > -1) res += w[link[i]][i];
  return res;
}
int a[2010];
int main() {
  int i, j;
  scanf("%d", &n);
  for (i = 1; i <= n; i++) scanf("%d", &a[i]);
  nx = ny = n;
  for (i = 1; i <= n; i++)
    for (j = 1; j <= n; j++) w[i][j] = a[i] * ((i < j) ? (j - i) : (i - j));
  int ans = KM();
  printf("%d\n", ans);
  return 0;
}
