#include<cstdio>
#include<cstring>
#include<algorithm>
#define mk make_pair
using namespace std;
typedef long long ll;
const int N=2010;

int n;
pair<ll,ll> a[N];
ll f[N][N];
//f[i][j]表示前j-i+1个数选[i,j] 

int main() {
	scanf("%d",&n);
	for(int i=1;i<=n;i++) {
		ll x; scanf("%lld",&x);
		a[i]=mk(x,i);
	}
	sort(a+1,a+n+1);
	for(int i=1;i<=n;i++) f[i][i]=a[1].first*abs(a[1].second-i);
	for(int k=2;k<=n;k++) {
		int x=a[k].first,y=a[k].second;
		for(int i=1,j=k;j<=n;i++,j++) 
			f[i][j]=max(f[i][j-1]+x*llabs(y-j),f[i+1][j]+x*llabs(y-i));
	}
	printf("%lld\n",f[1][n]); return 0;
}
	