#include<bits/stdc++.h>
using namespace std;
using ll=long long;
ll dp[2004][2004];
struct node{
	ll id,act;
}a[2004];
bool cmp(node a,node b){
	if(a.act!=b.act)return a.act>b.act;
	else return a.id<b.id;
}
int main(){
	ll n;
	scanf("%lld",&n);
	for(ll i=0;i<n;i++){
		scanf("%lld",&a[i].act);
		a[i].id=i;
	}
	sort(a,a+n,cmp);
	ll ans=0;
	for(int l=0;l<n;l++){
		for(int r=0;r<n;r++){
			int i=l+r;
			if(i>=n)break;
			
			ll act=a[i].act;
			ll loc=a[i].id;
			
			dp[l+1][r]=max(dp[l+1][r],dp[l][r]+act*abs(l-loc));
			dp[l][r+1]=max(dp[l][r+1],dp[l][r]+act*abs((n-1)-loc-r));
			
			ans=max(ans,dp[l+1][r]);
			ans=max(ans,dp[l][r+1]);
		}
	}
	printf("%lld\n",ans);
}