#include <bits/stdc++.h>
using namespace std;
using LL = long long;
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
namespace R {
const int maxn = 2000 + 10;
int n, m;
long long left[maxn], L[maxn], R[maxn];
long long w[maxn][maxn], slack[maxn];
bool visL[maxn], visR[maxn];
bool dfs(int u) {
  visL[u] = true;
  for (decay<decltype(m)>::type v = (0), _v = (m); v < _v; ++v) {
    if (visR[v]) continue;
    long long t = L[u] + R[v] - w[u][v];
    if (t == 0) {
      visR[v] = true;
      if (left[v] == -1 || dfs(left[v])) {
        left[v] = u;
        return true;
      }
    } else
      slack[v] = min(slack[v], t);
  }
  return false;
}
int go() {
  memset(left, -1, sizeof left);
  memset(R, 0, sizeof R);
  memset(L, 0, sizeof L);
  for (decay<decltype(n)>::type i = (0), _i = (n); i < _i; ++i)
    for (decay<decltype(m)>::type j = (0), _j = (m); j < _j; ++j)
      L[i] = max(L[i], w[i][j]);
  for (decay<decltype(n)>::type i = (0), _i = (n); i < _i; ++i) {
    memset(slack, 0x3f, sizeof slack);
    while (1) {
      memset(visL, 0, sizeof visL);
      memset(visR, 0, sizeof visR);
      if (dfs(i)) break;
      long long d = 1e18;
      for (decay<decltype(m)>::type j = (0), _j = (m); j < _j; ++j)
        if (!visR[j]) d = min(d, slack[j]);
      for (decay<decltype(n)>::type j = (0), _j = (n); j < _j; ++j)
        if (visL[j]) L[j] -= d;
      for (decay<decltype(m)>::type j = (0), _j = (m); j < _j; ++j)
        if (visR[j])
          R[j] += d;
        else
          slack[j] -= d;
    }
  }
  long long ret = 0;
  for (decay<decltype(m)>::type i = (0), _i = (m); i < _i; ++i)
    if (left[i] != -1) ret += w[left[i]][i];
  return ret;
}
}  // namespace R
long long a[2020];
int main() {
  int n;
  scanf("%d", &n);
  R::n = R::m = n;
  for (int i = 0; i < n; i++) {
    scanf("%lld", &a[i]);
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      R::w[i][j] = 1ll * abs(i - j) * (a[i]);
    }
  }
  long long ans = R::go();
  printf("%lld\n", ans);
  return 0;
}
