#include <bits/stdc++.h>
using namespace std;
const long long N = 5000 + 10, M = 5e4 + 10;
long long maxflow, mincost;
long long last[N], pre[N], dis[N], flow[N], pos = 1, head[N];
bool vis[N];
struct Edge {
  long long next, to, flow, dis;
} edge[M << 1];
void init() {
  pos = 1;
  memset(head, 0, sizeof head);
  mincost = maxflow = 0;
}
void add(long long from, long long to, long long flow, long long dis) {
  edge[++pos].next = head[from];
  edge[pos].flow = flow;
  edge[pos].dis = dis;
  edge[pos].to = to;
  head[from] = pos;
  edge[++pos].next = head[to];
  edge[pos].flow = 0;
  edge[pos].dis = -dis;
  edge[pos].to = from;
  head[to] = pos;
}
bool spfa(long long s, long long t) {
  memset(dis, 0x3f, sizeof dis);
  memset(flow, 0x3f, sizeof flow);
  memset(vis, 0, sizeof vis);
  queue<long long> q;
  dis[s] = 0;
  pre[t] = -1;
  q.push(s);
  vis[s] = 1;
  long long tot = 0;
  while (!q.empty()) {
    long long now = q.front();
    q.pop();
    vis[now] = 0;
    for (long long i = head[now]; i; i = edge[i].next) {
      long long to = edge[i].to;
      if (edge[i].flow > 0 && dis[to] > dis[now] + edge[i].dis) {
        dis[to] = edge[i].dis + dis[now];
        flow[to] = min(edge[i].flow, flow[now]);
        last[to] = i;
        pre[to] = now;
        if (!vis[to]) {
          q.push(to);
          vis[to] = 1;
        }
      }
    }
  }
  return pre[t] != -1;
}
void MCMF(long long s, long long t) {
  while (spfa(s, t)) {
    long long now = t;
    maxflow += flow[t];
    mincost += flow[t] * dis[t];
    while (now != s) {
      edge[last[now]].flow -= flow[t];
      edge[last[now] ^ 1].flow += flow[t];
      now = pre[now];
    }
  }
}
long long s, t;
int main() {
  long long n;
  cin >> n;
  s = 2 * n + 1;
  t = s + 1;
  for (long long i = 1; i <= n; i++) {
    add(s, i, 1, 0);
    add(i + n, t, 1, 0);
    long long x;
    scanf("%lld", &x);
    for (long long j = 1; j <= n; j++) add(i, j + n, 1, -(abs(i - j) * x));
  }
  MCMF(s, t);
  printf("%lld\n", -mincost);
}
