#include <cstdio>
#include <iostream>
#include <cstring>
#include <cmath>
using namespace std;


typedef long long LL;

const int N = 2005, M = N * N * 2 + 4 * N, L = 4010;
const LL INF = 0xcfcfcfcfcfcfcfcf;


int n, a[N], s, t, pre[L], incf[L];

LL maxflow, cost, d[L];
int q[L];
int head[L], numE = 1;
bool vis[L];
struct E{
	int next, v, w;
	LL c;
} e[M];
void inline add(int u, int v, int w, LL c) {
	e[++numE] = (E) { head[u], v, w, c };
	head[u] = numE;
}
bool spfa() {
    memset(vis, false, sizeof vis);
	memset(d, 0xcf, sizeof d);
	int hh = 0, tt = 1;
	q[0] = s; d[s] = 0; incf[s] = 2e9;
	while (hh != tt) {
		int u = q[hh++]; vis[u] = false;
		if (hh == L) hh = 0;
		for (int i = head[u]; i; i = e[i].next) {
			int v = e[i].v;
			if (e[i].w && d[u] + e[i].c > d[v]) {
				d[v] = d[u] + e[i].c;
				pre[v] = i;
				incf[v] = min(incf[u], e[i].w);
				if (!vis[v]) {
					q[tt++] = v;
					vis[v] = true;
					if (tt == L) tt = 0;
				}
			}
		}
	} 
	return d[t] != INF;
}
void update() {
	int x = t;
	while (x != s) {
		int i = pre[x];
		e[i].w -= incf[t], e[i ^ 1].w += incf[t];
		x = e[i ^ 1].v;
	}
	maxflow += incf[t];
	cost += d[t] * incf[t];
}

int main() {
	scanf("%d", &n);
	s = 2 * n + 1, t = 2 * n + 2;
	for (int i = 1; i <= n; i++) scanf("%d", a + i);

	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= n; j++) {
			add(i, n + j, 1, (LL)a[i] * abs(i - j));
			add(n + j, i, 0, -(LL)a[i] * abs(i - j));
		}
	}

	for (int i = 1; i <= n; i++) {
		add(s, i, 1, 0);
		add(i, s, 0, 0);
		add(i + n, t, 1, 0);
		add(t, i + n, 0, 0);
	}

	while (spfa()) update();
	printf("%lld\n", cost);
	return 0;
}