#include <bits/stdc++.h>
using namespace std;

vector<pair<int, int> > a(2010);
long dp[2010][2010];

template<class T> inline bool chmax(T &a, const T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}

int main(){
	int n, x;
	scanf("%d", &n);
	for(int i = 0; i < n; i++) {
		scanf("%d", &x);
		a.push_back(make_pair(x, i));
	}
	sort(a.begin(), a.end(), greater<pair<int, int> >());
	long ans = 0;
	for(int i = 0; i < n; i++) {
		for(int l = 0; l <= i; l++) {
			int r = i - l;
			chmax(dp[i+1][l+1], dp[i][l] + (long)a[i].first * abs(l - a[i].second));
			chmax(dp[i+1][l], dp[i][l] + (long)a[i].first * abs((n-1-r) - a[i].second));
		}
	}
	for(int i = 0; i < n; i++) chmax(ans, dp[n][i]);
	printf("%ld\n", ans);
}