#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;

long long n,a[2009],dp[2009][2009],id[2009],ans;
bool cmp(long long b1,long long b2){return a[b1]>a[b2];}

int main()
{
	cin >> n;
	for(long long i = 1;i<=n;i++)cin >> a[i],id[i] = i;
	sort(id+1,id+n+1,cmp);
	for(long long i = 1;i<=n;i++)
	{
		dp[i][0] = dp[i-1][0]+a[id[i]]*(n-i+1-id[i]);//cout << "dp[" << i<<"]["<<0<<"]="<<dp[i][0]<<endl;//
		for(long long j = 1;j<i;j++)
		{
			dp[i][j] = max(dp[i-1][j]+a[id[i]]*abs(n-(i-1-j)-id[i]),dp[i-1][j-1]+a[id[i]]*abs(id[i]-j));
			//cout << "dp[" << i<<"]["<<j<<"]="<<dp[i][j]<<endl;//
		}
		dp[i][i] = dp[i-1][i-1]+a[id[i]]*abs(id[i]-i);
	}
	for(int i = 0;i<=n;i++)if(ans<dp[n][i])ans = dp[n][i];
	cout << ans;
	return 0;
}