#include<bits/stdc++.h>
#define ll long long
using namespace std;
const ll p=1e9+7;
struct aaa{
	ll x,y;
}a[2010];
ll n,ans,f[2010][2010];
bool cmp(aaa a,aaa b){
	return a.x>b.x;
}
int main(){
	ll i,j,w,x;
	scanf("%lld",&n);
	for(i=1;i<=n;i++){
		scanf("%lld",&a[i].x);
		a[i].y=i;
	}
	sort(a+1,a+n+1,cmp);
	for(i=1;i<=n;i++){
		for(j=0;j<i;j++){
			w=a[i].x*abs(a[i].y-j-1);
			f[i][j+1]=max(f[i][j+1],f[i-1][j]+w);
			x=n-(i-1-j);
			w=a[i].x*abs(a[i].y-x);
			f[i][j]=max(f[i][j],f[i-1][j]+w);
		}
	}
	for(i=0;i<=n;i++)ans=max(ans,f[n][i]);
	printf("%lld",ans);
}