#include <bits/stdc++.h>
using namespace std;
const long long N = 100005;
char en = '\n';
long long inf = 1e16;
long long mod = 1e9 + 7;
long long power(long long x, long long n, long long mod) {
  long long res = 1;
  x %= mod;
  while (n) {
    if (n & 1) res = (res * x) % mod;
    x = (x * x) % mod;
    n >>= 1;
  }
  return res;
}
long long INF = inf;
long long hungarian(vector<vector<long long>> cost) {
  long long n = (long long)cost.size() - 1;
  long long m = (long long)cost[0].size() - 1;
  vector<long long> u(n + 1), v(m + 1), p(m + 1), way(m + 1);
  for (long long i = 1; i <= n; ++i) {
    p[0] = i;
    long long j0 = 0;
    vector<long long> minv(m + 1, INF);
    vector<char> used(m + 1, false);
    do {
      used[j0] = true;
      long long i0 = p[j0], delta = INF, j1;
      for (long long j = 1; j <= m; ++j)
        if (!used[j]) {
          long long cur = cost[i0][j] - u[i0] - v[j];
          if (cur < minv[j]) minv[j] = cur, way[j] = j0;
          if (minv[j] < delta) delta = minv[j], j1 = j;
        }
      for (long long j = 0; j <= m; ++j)
        if (used[j])
          u[p[j]] += delta, v[j] -= delta;
        else
          minv[j] -= delta;
      j0 = j1;
    } while (p[j0] != 0);
    do {
      long long j1 = way[j0];
      p[j0] = p[j1];
      j0 = j1;
    } while (j0);
  }
  vector<long long> assignment(n + 1);
  for (long long j = 1; j <= m; ++j) assignment[p[j]] = j;
  long long ret = 0;
  for (long long i = 1; i <= n; ++i) {
    ret += cost[i][assignment[i]];
  }
  return ret;
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long n;
  cin >> n;
  long long arr[n + 5];
  for (long long i = 1; i <= n; i++) cin >> arr[i];
  vector<vector<long long>> cost;
  cost.resize(n + 1, vector<long long>(n + 1));
  for (long long i = 1; i <= n; i++) {
    for (long long j = 1; j <= n; j++) {
      cost[i][j] = -abs(i - j) * arr[i];
    }
  }
  cout << -hungarian(cost) << en;
  return 0;
}
