#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int>P;
const double eps = 1e-8;
const int NINF = 0xc0c0c0c0;
const int INF  = 0x3f3f3f3f;
const ll  mod  = 1e9 + 7;
const ll  maxn = 1e6 + 5;
const int N = 2e3 + 5;

ll n,dp[N][N];
vector<pair<ll,int> >V(n);

ll DP(int L,int R){
	if(R<L) return 0;
	if(dp[L][R]!=-1) return dp[L][R];
	int i=L+n-1-R;
	return dp[L][R]=max(V[i].first*abs(V[i].second-L)+DP(L+1,R),V[i].first*abs(V[i].second-R)+DP(L,R-1));
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin>>n;
	for(int i=0;i<n;i++){int x;cin>>x; V.push_back({x,i});}
	sort(V.rbegin(),V.rend());
	memset(dp,-1,sizeof(dp));
	cout<<DP(0,n-1);
	return 0;
}