#include <iostream>
#include <cmath>
#include <utility>
#include <algorithm>
#include <cstring>

using namespace std;

typedef pair<int,int> pii;
typedef long long ll;
typedef pair<ll,ll> pll;
#define mp make_pair
#define x first
#define y second

pll sor[2003];
ll arr[2003],dp[2003][2003];

ll rek(int x,int y){
	if(x>y) return 0ll;
	if(dp[x][y]!=-1ll) return dp[x][y];
	int k=y-x+1;
	dp[x][y]=0ll;
	dp[x][y]=max(sor[k].x*(abs(sor[k].y-x))+rek(x+1,y),sor[k].x*(abs(sor[k].y-y))+rek(x,y-1));
	return dp[x][y];
}

int main () {
	ll n;
	cin>>n;
	memset(dp,-1ll,sizeof dp);
	for(ll i=1ll;i<=n;i++){
		cin>>arr[i];
		sor[i]=mp(arr[i],i);
	}
	sort(sor+1,sor+n+1);
	cout<<rek(1,n);



return 0;
}

