#include <bits/stdc++.h>
using namespace std;
const int nm = 2002;
const int maxn = nm;
const long long inf = 2e12 + 1;
struct Hungary {
  int nx, ny, maty[maxn], which[maxn];
  long long cost[maxn][maxn], fx[maxn], fy[maxn], dist[maxn];
  bool used[maxn];
  void init(int _nx, int _ny) {
    nx = _nx;
    ny = _ny;
    memset(fx, 0, sizeof(fx));
    memset(fy, 0, sizeof(fy));
    for (int i = (0); i <= (nx); ++i)
      for (int j = (0); j <= (ny); ++j) cost[i][j] = inf;
  }
  void add(int x, int y, long long c) { cost[x][y] = c; }
  long long mincost() {
    for (int x = (1); x <= (nx); ++x) {
      int y0 = 0;
      maty[0] = x;
      for (int y = (0); y <= (ny); ++y) {
        dist[y] = inf + 1;
        used[y] = false;
      }
      do {
        used[y0] = true;
        int x0 = maty[y0], y1;
        long long delta = inf + 1;
        for (int y = (1); y <= (ny); ++y)
          if (!used[y]) {
            long long curdist = cost[x0][y] - fx[x0] - fy[y];
            if (curdist < dist[y]) {
              dist[y] = curdist;
              which[y] = y0;
            }
            if (dist[y] < delta) {
              delta = dist[y];
              y1 = y;
            }
          }
        for (int y = (0); y <= (ny); ++y)
          if (used[y]) {
            fx[maty[y]] += delta;
            fy[y] -= delta;
          } else
            dist[y] -= delta;
        y0 = y1;
      } while (maty[y0] != 0);
      do {
        int y1 = which[y0];
        maty[y0] = maty[y1];
        y0 = y1;
      } while (y0);
    }
    long long ret = 0;
    for (int y = (1); y <= (ny); ++y) {
      int x = maty[y];
      if (cost[x][y] < inf) ret += cost[x][y];
    }
    return ret;
  }
} hungary;
int n;
long long a[nm];
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    scanf("%lld", &a[i]);
  }
  long long cmax = 0;
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= n; ++j) {
      cmax = max(cmax, a[i] * abs(i - j));
    }
  }
  hungary.init(n, n);
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= n; ++j) {
      hungary.add(i, j, cmax - a[i] * abs(i - j));
    }
  }
  long long res = hungary.mincost();
  cout << cmax * n - res << "\n";
}
