#include <bits/stdc++.h>
using namespace std;
const int N = 2010;
const int M = 2e6 + 4e3 + 7;
const long long INF = 1e18;
const int inf = 0x3f3f3f3f;
int n, a[N];
int s, t;
struct edge {
  int v, cap;
  long long cost;
  int nxt;
} e[M << 1];
int tot, head[N << 1];
int q[N << 2], top, tail, p[N << 1], f[N << 1];
long long d[N];
bool inq[N << 1];
void init(void) {
  tot = 0;
  memset(head, -1, sizeof head);
}
void addedge(int u, int v, int cap, long long cost) {
  e[tot] = (edge){v, cap, cost, head[u]};
  head[u] = tot++;
  e[tot] = (edge){u, 0, -cost, head[v]};
  head[v] = tot++;
}
bool BellmanFord(int s, int t, int& flow, long long& cost) {
  for (int i = 0; i <= 2 * n + 1; ++i) {
    inq[i] = false;
    d[i] = INF;
    f[i] = 0;
  }
  top = tail = 0;
  q[tail++] = s;
  d[s] = 0, inq[s] = true, f[s] = inf;
  while (top != tail) {
    int u = q[top++];
    inq[u] = false;
    for (int i = head[u]; i != -1; i = e[i].nxt) {
      int v = e[i].v, cap = e[i].cap;
      long long cost = e[i].cost;
      if (cap && d[v] > d[u] + cost) {
        d[v] = d[u] + cost;
        p[v] = i;
        f[v] = min(cap, f[u]);
        if (!inq[v]) {
          inq[v] = true;
          q[tail++] = v;
        }
      }
    }
  }
  if (f[t] == 0) return false;
  cost += 1ll * d[t] * f[t], flow += f[t];
  for (int i = t; i != s; i = e[p[i] ^ 1].v) {
    e[p[i]].cap -= f[t];
    e[p[i] ^ 1].cap += f[t];
  }
  return true;
}
long long mcmf(int s, int t) {
  long long mincost = 0;
  int flow = 0;
  while (BellmanFord(s, t, flow, mincost))
    ;
  return mincost;
}
int main(void) {
  ios::sync_with_stdio(false), cin.tie(0);
  init();
  cin >> n;
  s = 0, t = 2 * n + 1;
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
    addedge(s, i, 1, 0);
    addedge(n + i, t, 1, 0);
  }
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= n; ++j) {
      long long tmp = 1ll * abs(i - j) * a[i];
      addedge(i, n + j, 1, -tmp);
    }
  }
  cout << -mcmf(s, t) << endl;
  return 0;
}
