#include<bits/stdc++.h>

using namespace std;

typedef long long LL;
typedef pair<LL,LL>PII;

const int N=2050;

int n;
LL dp[N][N];
PII p[N];

LL solve(int idx,int mi,int mx)
{
	if(idx>n) return 0;
	if(dp[idx][mi]!=-1) return dp[idx][mi];
	LL op1=solve(idx+1,mi+1,mx)+(LL)p[idx].first*abs(p[idx].second-mi);
	LL op2=solve(idx+1,mi,mx-1)+(LL)p[idx].first*abs(p[idx].second-mx);
	return dp[idx][mi]=max(op1,op2);
}

int main()
{
	cin>>n;
	for(int i=1;i<=n;i++) {
		cin>>p[i].first;
		p[i].second=i;
	}
	
	sort(p+1,p+1+n);
	for(int i=1;i<=n/2;i++) {
		swap(p[i],p[n-i+1]);
	}
	memset(dp,-1,sizeof dp);
	cout<<solve(1,1,n);
 	return 0;
} 