#include <bits/stdc++.h>
#define INF 1000000000
#define LINF 1000000000000000000
#define MOD 1000000007
#define mod 1000007
#define INF63 1061109567
#define INF127 9187201950435737471
#define UINF 18446744073709551615
#define F first
#define S second
#define ll long long
#define N 2010
using namespace std;
ll n,dp[N][N],ans=0;
pair<ll,ll> a[N];
int main(){
	ll i,j,k;
	cin>>n;
	for(i=0;i<n;i++)
	{
		cin>>a[i].F;
		a[i].S=i;
	}
	sort(a,a+n);
	reverse(a,a+n);
	memset(dp,0,sizeof(dp));
	for(i=0;i<n;i++)
	{
		for(j=0;j<=i;j++)
		{
			k=i-j;
			dp[j+1][k]=max(dp[j+1][k],dp[j][k]+abs(a[i].S-j)*a[i].F);
			dp[j][k+1]=max(dp[j][k+1],dp[j][k]+abs(a[i].S-(n-k-1))*a[i].F);
		}
	}
	for(i=0;i<n;i++)
	{
		ans=max(ans,dp[i][n-i]);
	}
	cout<<ans<<endl;
	return 0;
}
