#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <typename T>
T hungarian(vector<vector<T>> &A) {
  const T infty = numeric_limits<T>::max();
  const int N = (int)A.size();
  const int M = (int)A[0].size();
  vector<int> P(M), way(M);
  vector<T> U(N, 0), V(M, 0), minV;
  vector<bool> used;
  for (int i = 1; i < N; i++) {
    P[0] = i;
    minV.assign(M, infty);
    used.assign(M, false);
    int j0 = 0;
    while (P[j0] != 0) {
      int i0 = P[j0], j1 = 0;
      used[j0] = true;
      T delta = infty;
      for (int j = 1; j < M; j++) {
        if (used[j]) continue;
        T curr = A[i0][j] - U[i0] - V[j];
        if (curr < minV[j]) minV[j] = curr, way[j] = j0;
        if (minV[j] < delta) delta = minV[j], j1 = j;
      }
      for (int j = 0; j < M; j++) {
        if (used[j])
          U[P[j]] += delta, V[j] -= delta;
        else
          minV[j] -= delta;
      }
      j0 = j1;
    }
    do {
      P[j0] = P[way[j0]];
      j0 = way[j0];
    } while (j0 != 0);
  }
  return -V[0];
}
void solve(int N, vector<long> A) {
  vector<vector<ll>> M(N + 1, vector<ll>(N + 1));
  for (int i = 0; i < (N); ++i)
    for (int j = 0; j < (N); ++j) M[i + 1][j + 1] = -A[i] * abs(i - j);
  cout << -hungarian(M) << endl;
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  vector<long> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  solve(N, move(A));
  return 0;
}
