#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N=2010,INF=1e9;
const ll P=1e18;
int s,t,n,link[N<<1],incf[N<<1],pre[N<<1],vis[N],tot=1;
ll c[N<<1],dis[N<<1],ans;
struct edge{int y,v,next;ll c;}a[N*N*2];
inline int read()
{
	int x=0,ff=1;
	char ch=getchar();
	while(!isdigit(ch)) {if(ch=='-') ff=-1;ch=getchar();}
	while(isdigit(ch)) {x=(x<<1)+(x<<3)+(ch^48);ch=getchar();}
	return x*ff;
}
inline void add(int x,int y,int v,ll c)
{
	a[++tot].y=y;a[tot].v=v;a[tot].c=c;a[tot].next=link[x];link[x]=tot;
	a[++tot].y=x;a[tot].v=0;a[tot].c=-c;a[tot].next=link[y];link[y]=tot;
}
inline bool spfa()
{
	queue<int>q;q.push(s);
	for(int i=s;i<=t;++i) dis[i]=-1;
	memset(vis,0,sizeof(vis));
	dis[s]=0;incf[s]=INF;vis[s]=1;
	while(!q.empty())
	{
		int x=q.front();q.pop();vis[x]=0;
		for(int i=link[x];i;i=a[i].next)
		{
			int y=a[i].y;
			if(!a[i].v) continue;
			if(dis[y]<dis[x]+a[i].c)
			{
				dis[y]=dis[x]+a[i].c;
				incf[y]=min(incf[x],a[i].v);
				pre[y]=i;
				if(!vis[y]) vis[y]=1,q.push(y);
			}
		}
	}
	if(dis[t]==-1) return false;
	return true;
}
inline void updata()
{
	int x=t;
	while(x!=s)
	{
		int i=pre[x];
		a[i].v-=incf[t];
		a[i^1].v+=incf[t];
		x=a[i^1].y;
	}
	ans+=dis[t]*incf[t];
}
int main()
{
	//freopen("1.in","r",stdin);
	n=read();
	s=0;t=n<<1|1;
	for(int i=1;i<=n;++i) c[i]=read();
	for(int i=1;i<=n;++i)
		for(int j=1;j<=n;++j) add(i,j+n,1,(ll)abs(i-j)*c[i]);
	for(int i=1;i<=n;++i) add(s,i,1,0);
	for(int i=1;i<=n;++i) add(i+n,t,1,0);
	while(spfa()) updata();
	printf("%lld",ans);	
	return 0;
}
