#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define fi first
#define se second
using pll = pair<ll,ll>;
ll n;
ll ans=0;
vector<pll> vt;   //存value和index 
ll dp[2005][2005];
ll cal(ll a,ll b,ll cnt){
	if(a>b) return 0;
	if(dp[a][b]!=-1) return dp[a][b];
	return dp[a][b] = max(cal(a+1 , b , cnt+1) + vt[cnt].fi*abs(vt[cnt].se-a) , cal(a,b-1,cnt+1) + vt[cnt].fi*abs(vt[cnt].se -b));
}
int main(){
	//freopen("in.txt","r",stdin);
	cin>>n;
	ll t;
	for(ll i=0;i<n;i++){
		cin>>t;
		vt.emplace_back(t,i) ;
	}
	sort(vt.begin() , vt.end() , [](pll x,pll y){if(x.fi != y.fi) return x.fi>y.fi; return x.se>y.se;});  //可以直接用greater
	memset(dp,-1,sizeof(dp));
	cout<<cal(0,n-1,0)<<endl;
	return 0;
}