#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <queue>
using namespace std;
#define MAXN 100100
#define ll long long
#define inf 1<<30
ll n, m, flag[MAXN], comu[MAXN], s, t, dis[MAXN], ans1, ans2, cnt, a[MAXN];
struct node
{
	ll v, w, c;
	node *next, *rev;
}pool[8000100], *h[MAXN], *comp[MAXN];
void addedge(ll u, ll v, ll c, ll w)
{
	node *p = &pool[++cnt], *q = &pool[++cnt];
	p->v = v; p->next = h[u]; p->c = c; p->w = w; p->rev = q; h[u] = p;
	q->v = u; q->next = h[v]; q->c = 0; q->w = -w; q->rev = p; h[v] = q;
}
queue<ll> Q;
bool Spfa()
{
	for(ll i=1;i<=t;i++) dis[i] = inf;
	dis[s] = 0;
	Q.push(s);
	ll u, v;
	while(!Q.empty())
	{
		u = Q.front();
		Q.pop();
		flag[u] = 0;
		for(node *p = h[u]; p; p = p->next)
		{
			if(dis[v=p->v] > dis[u] + p->w && p->c != 0)
			{
				dis[v] = dis[u] + p->w;
				comu[v] = u;
				comp[v] = p;
				if(flag[v] == 0) Q.push(v), flag[v]=1;
			}
		}
	}
	if(dis[t] != inf) return true;
	else return false;
}
ll find()
{
	ll u=t, Min = inf;
	while(u!=s)
	{
		Min = min(Min, comp[u]->c);
		u = comu[u];
	}
	u = t;
	while(u!=s)
	{
		comp[u]->c -= Min;
		comp[u]->rev->c += Min;
		u = comu[u];
	}
	return Min;
}
void mincostflow()
{
	ll as = 0;
	while(Spfa() == true)
	{
		as = find();
		ans1 += as;
		ans2 += as*dis[t];
	}
}
int main()
{
	scanf("%lld",&n);
	s = 0; t = 2*n+1;
	for(ll i=1;i<=n;i++) scanf("%lld",&a[i]);
	for(ll i=1;i<=n;i++)
	{
		addedge(s, i, 1, 0);
		addedge(i+n, t, 1, 0);
		for(ll j=1;j<=n;j++)
		{
			addedge(i, j+n, 1, -abs(j-i)*a[i]);
		}
	}
	mincostflow();
	printf("%lld\n",-ans2);
	
	return 0;
}