#include <bits/stdc++.h>
using namespace std;
template <typename T>
struct hungarian {
  const T inf = numeric_limits<T>::max();
  int n, m, max_match, root;
  T max_cost;
  vector<vector<T>> cost;
  vector<T> lx, ly, slack;
  vector<int> xy, yx, prev, slackx;
  vector<bool> s, t;
  void update_labels() {
    T delta = inf;
    for (int y = 0; y < m; y++)
      if (!t[y]) delta = min(delta, slack[y]);
    for (int x = 0; x < n; x++)
      if (s[x]) lx[x] -= delta;
    for (int y = 0; y < m; y++)
      if (t[y]) ly[y] += delta;
    for (int y = 0; y < m; y++)
      if (!t[y]) slack[y] -= delta;
  }
  void add_to_tree(int x, int prevx) {
    s[x] = true;
    prev[x] = prevx;
    for (int y = 0; y < m; y++) {
      if (lx[x] + ly[y] - cost[x][y] < slack[y]) {
        slack[y] = lx[x] + ly[y] - cost[x][y];
        slackx[y] = x;
      }
    }
  }
  void augment() {
    if (max_match == n) return;
    fill(s.begin(), s.end(), false);
    fill(t.begin(), t.end(), false);
    fill(prev.begin(), prev.end(), -1);
    queue<int> que;
    for (int x = 0; x < n; x++) {
      if (xy[x] == -1) {
        root = x;
        que.push(x);
        prev[x] = -2;
        s[x] = true;
        break;
      }
    }
    for (int y = 0; y < m; y++) {
      slack[y] = lx[root] + ly[y] - cost[root][y];
      slackx[y] = root;
    }
    int x, y;
    while (1) {
      while (!que.empty()) {
        x = que.front();
        que.pop();
        for (y = 0; y < m; y++) {
          if (cost[x][y] == lx[x] + ly[y] && !t[y]) {
            if (yx[y] == -1) break;
            t[y] = true;
            que.push(yx[y]);
            add_to_tree(yx[y], x);
          }
        }
        if (y < m) break;
      }
      if (y < m) break;
      update_labels();
      for (y = 0; y < m; y++) {
        if (!t[y] && slack[y] == 0) {
          if (yx[y] == -1) {
            x = slackx[y];
            break;
          } else {
            t[y] = true;
            que.push(yx[y]);
            add_to_tree(yx[y], slackx[y]);
          }
        }
      }
      if (y < m) break;
    }
    if (y < m) {
      max_match++;
      for (int cx = x, cy = y, ty; cx != -2; cx = prev[cx], cy = ty) {
        ty = xy[cx];
        yx[cy] = cx, xy[cx] = cy;
      }
      augment();
    }
  }
  hungarian(const vector<vector<T>> &cost)
      : max_match(0),
        max_cost(0),
        cost(cost),
        n(cost.size()),
        m(cost[0].size()),
        lx(n, -inf),
        ly(m),
        xy(n, -1),
        yx(m, -1),
        s(n),
        t(m),
        prev(n),
        slack(m),
        slackx(m) {
    for (int x = 0; x < n; x++)
      for (int y = 0; y < m; y++) lx[x] = max(lx[x], cost[x][y]);
    augment();
    for (int x = 0; x < n; x++) max_cost += cost[x][xy[x]];
  }
};
int main() {
  int n;
  cin >> n;
  long long int a[2020];
  for (int i = 0; i < n; i++) cin >> a[i];
  vector<vector<long long int>> c(n, vector<long long int>(n));
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      c[i][j] = a[i] * abs(i - j);
    }
  }
  hungarian<long long int> h(c);
  cout << h.max_cost << endl;
  return 0;
}
