#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 2010;
const ll INF = 1e18;
int nx, ny;
ll g[N][N];
int linker[N];
ll lx[N], ly[N];
ll slack[N];
bool visx[N], visy[N];
bool DFS(int x) {
  visx[x] = true;
  for (int y = 0; y < ny; y++) {
    if (visy[y]) continue;
    ll tmp = lx[x] + ly[y] - g[x][y];
    if (tmp == 0) {
      visy[y] = true;
      if (linker[y] == -1 || DFS(linker[y])) {
        linker[y] = x;
        return true;
      }
    } else {
      if (slack[y] > tmp) slack[y] = tmp;
    }
  }
  return false;
}
ll KM() {
  memset(linker, -1, sizeof(linker));
  memset(ly, 0, sizeof(ly));
  for (int i = 0; i < nx; i++) {
    lx[i] = -INF;
    for (int j = 0; j < ny; j++) {
      if (g[i][j] > lx[i]) {
        lx[i] = g[i][j];
      }
    }
  }
  for (int x = 0; x < nx; x++) {
    for (int i = 0; i < ny; i++) {
      slack[i] = INF;
    }
    while (true) {
      memset(visx, 0, sizeof(visx));
      memset(visy, 0, sizeof(visy));
      if (DFS(x)) break;
      ll d = INF;
      for (int i = 0; i < ny; i++)
        if (!visy[i] && d > slack[i]) d = slack[i];
      for (int i = 0; i < nx; i++)
        if (visx[i]) lx[i] -= d;
      for (int i = 0; i < ny; i++) {
        if (visy[i])
          ly[i] += d;
        else
          slack[i] -= d;
      }
    }
  }
  ll res = 0;
  for (int i = 0; i < ny; i++) {
    if (linker[i] != -1) {
      res += g[linker[i]][i];
    }
  }
  return res;
}
ll a[N];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%lld", &a[i]);
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      g[i][j] = a[i + 1] * abs(i - j);
    }
  }
  nx = ny = n;
  printf("%lld\n", KM());
  return 0;
}
