#include <bits/stdc++.h>
using namespace std;
template <class c>
struct rge {
  c b, e;
};
template <class c>
rge<c> range(c i, c j) {
  return rge<c>{i, j};
}
template <class c>
auto dud(c *x) -> decltype(cerr << *x, 0);
template <class c>
char dud(...);
struct debug {
  template <class c>
  debug &operator<<(const c &) {
    return *this;
  }
};
using ii = pair<int, int>;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using ld = long double;
const int inf = 0x3f3f3f3f;
const ll linf = 0x3f3f3f3f3f3f3f3fLL;
template <typename T>
T abs(T x) {
  return x < 0 ? -x : x;
}
template <typename T>
void max_self(T &a, T b) {
  a = max(a, b);
}
template <typename T>
void min_self(T &a, T b) {
  a = min(a, b);
}
const int MAX = 2010;
long long mcost[MAX][MAX];
long long hung(const int &n, const int &m) {
  vector<long long> u(n + 1), v(m + 1), minv;
  vector<int> par(m + 1), next(m + 1);
  vector<bool> vstd;
  for (int i = 1; i <= n; ++i) {
    par[0] = i;
    int idj = 0;
    minv.assign(m + 1, inf);
    vstd.assign(m + 1, false);
    do {
      vstd[idj] = true;
      int idi = par[idj], temp;
      long long det = inf;
      for (int j = 1; j <= m; ++j)
        if (!vstd[j]) {
          long long cur = mcost[idi][j] - u[idi] - v[j];
          if (cur < minv[j]) minv[j] = cur, next[j] = idj;
          if (minv[j] < det) det = minv[j], temp = j;
        }
      for (int j = 0; j < m; ++j) {
        if (vstd[j])
          u[par[j]] += det, v[j] -= det;
        else
          minv[j] -= det;
      }
      idj = temp;
    } while (par[idj]);
    do {
      int temp = next[idj];
      par[idj] = par[temp];
      idj = temp;
    } while (idj);
  }
  return abs(v[0]);
}
void solve(int tc) {
  int n;
  cin >> n;
  vector<long long> v(n + 1);
  for (int i = 1; i <= n; ++i) {
    cin >> v[i];
  }
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= n; ++j) {
      mcost[i][j] = -v[i] * abs(i - j);
    }
  }
  cout << hung(n, n) << endl;
}
int main() {
  int tc = 1;
  ios::sync_with_stdio(false);
  cin.tie(0);
  for (int i = 1; i <= tc; ++i) solve(i);
  return 0;
}
