#include <cstdio>
#include <algorithm>
#define LL long long
#define MX (2000 + 233)
#define chkmx(a ,b) (a = max(a ,b))

LL max(LL a ,LL b){return a > b ? a : b;}
LL abs(LL a){return a > 0 ? a : -a;}
LL dp[MX][MX];

struct P{
	LL id ,A;
	bool operator <(const P &B)const{
		return A > B.A;
	}
}P[MX];

int main(){
	int n; scanf("%d" ,&n);
	for(int i = 1 ; i <= n ; ++i){
		scanf("%lld" ,&P[i].A);
		P[i].id = i;
	}std::sort(P + 1 ,P + 1 + n);
	LL Ans = 0;
	for(int i = 0 ; i <= n ; ++i){
		for(int j = 0 ; i + j < n ; ++j){
			int x = i + j + 1;
			chkmx(dp[i + 1][j] ,dp[i][j] + abs(P[x].id - (i + 1)) * P[x].A);
			chkmx(dp[i][j + 1] ,dp[i][j] + abs(P[x].id - (n - j)) * P[x].A);
		}
	}
	for(int i = 0 ; i <= n ; ++i)
		chkmx(Ans ,dp[i][n - i]);
	printf("%lld\n" ,Ans);
	return 0;
}