#include <bits/stdc++.h>
using namespace std;
int n;
long long dp[2005][2005];
vector<pair<long long,int> > v;
long long solve(int l,int r)
{
	if (r<l)
	return 0;
	if (dp[l][r]!=-1)
	return dp[l][r];
	int i=l+n-r-1;
	return dp[l][r]=max(v[i].first*abs(v[i].second-l)+solve(l+1,r),v[i].first*abs(v[i].second-r)+solve(l,r-1));
}
int main()
{
	scanf("%d",&n);
	for (int i=0;i<n;i++)
	{
		int a;
		scanf("%d",&a);
		v.push_back({a,i});
	}
	sort(v.rbegin(),v.rend());
	memset(dp,-1,sizeof(dp));
	printf("%lld",solve(0,n-1));
}