#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
const int Maxn=2e3+5;
int n;
long long tmp,ans,dp[Maxn][Maxn];
struct A
{
	int pos;
	long long val;
}num[Maxn];
bool cmp(A a,A b)
{
	return a.val>b.val;
}
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>tmp;
		num[i].val=tmp;
		num[i].pos=i;
	}
	sort(num+1,num+n+1,cmp);
	for(int i=1;i<=n;i++)
	{
		dp[i][0]=dp[i-1][0]+num[i].val*abs(num[i].pos-(n-i+1));
		dp[i][i]=dp[i-1][i-1]+num[i].val*abs(num[i].pos-i);
		for(int j=1;j<i;j++)
		{
			dp[i][j]=max(dp[i-1][j-1]+num[i].val*abs(num[i].pos-j),
						dp[i-1][j]+num[i].val*abs(num[i].pos-(n-i+j+1)));
		}
	}
	for(int i=1;i<=n;i++)
		ans=max(ans,dp[n][i]);
	cout<<ans;
	return 0;
}
