#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define MP make_pair
#define PII pair<int, int>
#define PLL pair<ll, ll>
#define PLI pair<ll, int>
#define PIL pair<int, ll>
#define STR string
#define Fst first
#define Snd second
#define SHN 1e9
#define LSHN 1e18
using namespace std;
int n;
PLL a[2010];
ll d[2010][2010];
ll dfs(int x,int y)
{
	if (d[x][y]!=-1) return d[x][y];
	int t=y-x+1;
	t=n-t;
	if (x==y) return abs(a[t].Snd-x)*a[t].Fst;
	return d[x][y]=max(dfs(x+1,y)+abs(a[t].Snd-x)*a[t].Fst,dfs(x,y-1)+abs(a[t].Snd-y)*a[t].Fst);
}
int main()
{
	cin >>n;
	for (ll i=0;i<n;i++) cin >>a[i].Fst,a[i].Snd=i;
	sort(a,a+n),reverse(a,a+n);
	memset(d,-1,sizeof(d));
	cout <<dfs(0,n-1);
	return 0;
}