#include <bits/stdc++.h>
using namespace std;
int MOD = 1000000007;
const long long inf = 2e9 * 3000;
const int maxn = 2020;
long long m[maxn][maxn];
bool book_l[maxn];
bool book_r[maxn];
long long val_l[maxn];
long long val_r[maxn];
int match[maxn];
long long slack[maxn];
int n;
bool dfs(int left) {
  book_l[left] = true;
  for (int right = 0; right < n; right++) {
    if (book_r[right]) continue;
    long long x = val_l[left] + val_r[right] - m[left][right];
    if (x == 0) {
      book_r[right] = true;
      if (match[right] == -1 || dfs(match[right])) {
        match[right] = left;
        return true;
      }
    } else {
      slack[right] = min(slack[right], x);
    }
  }
  return false;
}
long long km() {
  memset(match, -1, sizeof(match));
  memset(val_r, 0, sizeof(val_r));
  for (int i = 0; i < n; i++) {
    val_l[i] = m[i][0];
    for (int j = 1; j < n; j++) {
      val_l[i] = max(val_l[i], m[i][j]);
    }
  }
  for (int i = 0; i < n; i++) {
    fill(slack, slack + n, inf);
    while (1) {
      memset(book_l, false, sizeof(book_l));
      memset(book_r, false, sizeof(book_r));
      if (dfs(i)) break;
      long long v = inf;
      for (int j = 0; j < n; j++)
        if (!book_r[j]) v = min(v, slack[j]);
      for (int j = 0; j < n; j++) {
        if (book_l[j]) val_l[j] -= v;
        if (book_r[j])
          val_r[j] += v;
        else
          slack[j] -= v;
      }
    }
  }
  long long ans = 0;
  for (int i = 0; i < n; i++) ans += m[match[i]][i];
  return ans;
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n;
  vector<long long> a(n + 1);
  for (int i = 0; i < (n); ++i) {
    cin >> a[i];
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      m[i][j] = a[i] * abs(i - j);
    }
  }
  long long ret = km();
  cout << ret << endl;
  return 0;
}
