#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define mkp make_pair
#define fi first
#define se second
void read(int &x){
	scanf("%d",&x);
}
void write(ll x){
	if (x>9) write(x/10);
	putchar(x%10+'0'); 
}
int n;
pii a[2003];
bool cmp(pii A,pii B){return A.fi>B.fi;}
ll dp[2003][2003],ans;
int main(){
	read(n);
	for (int i=1;i<=n;i++) read(a[i].fi),a[i].se=i;
	sort (a+1,a+1+n,cmp);
	for (int i=0;i<=n;i++)
		for (int j=0;i+j<=n;j++){
			if (i>0)dp[i][j]=max(dp[i][j],dp[i-1][j]+1ll*abs(a[i+j].se-i)*a[i+j].fi);
			if (j>0)dp[i][j]=max(dp[i][j],dp[i][j-1]+1ll*abs(n-j+1-a[i+j].se)*a[i+j].fi);
		}
	for (int i=0;i<=n;i++) ans=max(ans,dp[i][n-i]);
	write(ans);
}