#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pi pair<int,int>
#define ff first
#define ss second
const int N = 2001;

int dp[N][N];
int n;
pi a[N];

int solve(int l,int r){
	if(l+r>=n)
		return 0;
	int &tmp = dp[l][r];
	if(tmp != -1)
		return tmp;
	tmp = solve(l+1,r)+abs(l+1-a[l+r+1].ss)*a[l+r+1].ff;
	tmp = max(tmp,solve(l,r+1)+abs(n-r-a[l+r+1].ss)*a[l+r+1].ff);
	return tmp;
}

int32_t main() { 
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>a[i].ff;
		a[i].ss=i;
	}

	sort(a+1,a+n+1,greater<pi>());
	memset(dp,-1,sizeof dp);
	int ans = solve(0,0);
	cout<<ans<<endl;
}
