#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<bitset>
#include<cmath>
#include<queue>
#include<map>
#include<set>

using namespace std;

int read()
{
	int ans=0,f=1;
	char c=getchar();
	while(c>'9'||c<'0'){if(c=='-')f=-1;c=getchar();}
	while(c>='0'&&c<='9'){ans=ans*10+c-'0';c=getchar();}
	return ans*f;
}

const int N=2005;
int n,a[N],h[N],l[N],tot,ans;

struct Node
{
	int x,y,z;
	bool operator < (const Node &t)const
	{
		return t.z<z;
	}
}b[N*N];

int main()
{
	n=read();
	for(int i=1;i<=n;++i)
		a[i]=read();
	for(int i=1;i<=n;++i)
		for(int j=1;j<=n;++j)
			b[++tot]=(Node){i,j,a[j]*fabs(i-j)};
	sort(b+1,b+1+tot);
	for(int i=1;i<=tot;++i)
		if(!h[b[i].x]&&!l[b[i].y])
		{
			ans+=b[i].z;
			h[b[i].x]=1;
			l[b[i].y]=1;
		}
	printf("%d\n",ans);
	return 0;
}