#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll N=2e3+7;
ll dp[N][N];
struct stu{
	ll value,id;
	bool friend operator<(const stu &x,const stu &y){
		return x.value>y.value;
	}
}arr[N];
int main(){	
	ll n;
	cin>>n;
	for(ll i=1;i<=n;i++) {
		cin>>arr[i].value;
		arr[i].id=i;
	}
	sort(arr+1,arr+1+n); 
	for(ll i=1;i<=n;i++){
		for(ll l=0;l<i;l++){
			ll r=i-1-l; 
			dp[l+1][r]=max(dp[l+1][r],dp[l][r]+arr[i].value*abs(arr[i].id-l-1));
			dp[l][r+1]=max(dp[l][r+1],dp[l][r]+arr[i].value*abs(n-r-arr[i].id));
		}
	}
	ll ans=0;
	for(int i=0;i<=n;i++) ans=max(ans,dp[i][n-i]);
	cout<<ans<<endl;
	return 0;
}