#include <bits/stdc++.h>

using namespace std;
typedef long long int lld;

priority_queue<pair<lld,int> > q;
lld dp[2222][2222];
int main(void){
	int n;
	scanf("%d",&n);
	for(int e=1;e<=n;e++){
		lld a;
		scanf("%lld",&a);
		q.push(make_pair(a,e));
	}
	int num = 0;
	while(!q.empty()){
		lld val = q.top().first;
		int wh = q.top().second;
		q.pop();
		for(int q=0;q<=num;q++){
			int ll = q;
			int rr = n+1-(num-q);
			dp[ll+1][rr] = max(dp[ll+1][rr],dp[ll][rr]+val*(lld)abs((wh-(ll+1))));
			dp[ll][rr-1] = max(dp[ll][rr-1],dp[ll][rr]+val*(lld)abs((wh-(rr-1))));
		}
		num++;
	}
	lld ans = 0;
	for(int e=0;e<=n;e++){
		ans = max(ans,dp[e][e+1]);
	}
	printf("%lld",ans);
	return 0;
}
