#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstdlib>
#include<cstring>
#include<queue>
using namespace std;
inline int read()
{
	int x=0,f=1;char ch=getchar();
	while(ch<'0' || ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0' && ch<='9')x=x*10+ch-'0',ch=getchar();
	return x*f;
}
int stack[20];
inline void write(int x)
{
	if(x<0){putchar('-');x=-x;}
	if(!x){putchar('0');return;}
	int top=0;
	while(x)stack[++top]=x%10,x/=10;
	while(top)putchar(stack[top--]+'0');
}
inline void pr1(int x){write(x),putchar(' ');}
inline void pr2(int x){write(x),puts("");}
queue<int>q;
const int inf=0x3f3f3f3f;
struct node
{
	int x,y,c,next;long long w;
}a[10000010];int len,last[4010];
inline void trins(int x,int y,int c,long long w)
{
	len++;
	a[len].x=x;a[len].y=y;a[len].c=c;a[len].w=w;
	a[len].next=last[x];last[x]=len;
}
inline void ins(int x,int y,int c,long long w){trins(x,y,c,w),trins(y,x,0,-w);}
int st,ed,f[4010],pre[4010];
long long d[4010];
bool v[4010];
inline bool spfa()
{
	memset(d,-1,sizeof(d));f[ed]=-1;
	q.push(st);d[st]=0,f[st]=inf,v[st]=true;
	while(!q.empty())
	{
		int x=q.front();q.pop();
		for(int k=last[x];k;k=a[k].next)
		{
			if(!a[k].c)continue;
			int y=a[k].y;
			if(d[y]<d[x]+a[k].w)
			{
				d[y]=d[x]+a[k].w;
				f[y]=min(f[x],a[k].c),pre[y]=k;
				if(!v[y])v[y]=true,q.push(y);
			}
		}v[x]=false;
	}
	if(f[ed]==-1)return false;
	else return true;
}
int ans;
long long sum;
inline void update()
{
	int x=ed;
	while(x!=st)
	{
		int k=pre[x];
		a[k].c-=f[ed],a[k^1].c+=f[ed];
		x=a[k].x;
	}ans+=f[ed],sum+=f[ed]*d[ed];
}
int w[2010];
int main()
{
    //freopen("a.in","r",stdin);
    //freopen("a.out","w",stdout);
    int n=read();
    for(int i=1;i<=n;i++)w[i]=read();
    len=1;st=0,ed=2*n+1;
    for(int i=1;i<=n;i++)
    {
    	ins(st,i,1,0),ins(n+i,ed,1,0);
    	for(int j=1;j<=n;j++)ins(i,n+j,1,1LL*abs(i-j)*w[i]);
	}
	while(spfa()==true)update();
	printf("%lld\n",sum);
    return 0;
}