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

int64_t dp[2010][2010];
int main() {
	int n; cin >> n;
	pair<int64_t, int64_t> a[n];
	for(int i = 0; i < n; ++i) {
		cin >> a[i].first;
		a[i].second = i;
	}
	sort(a, a + n);
	reverse(a, a + n);
	for(int i = 0; i < n; ++i) {
		int64_t val, idx;
		tie(val, idx) = a[i];
		for(int j = 0; j <= i; ++j) {
			dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i][j] + val * abs(j - idx));
			dp[i + 1][j] = max(dp[i + 1][j], dp[i][j] + val * abs((n - 1) - (i - j) - idx));
		}
	}
	int64_t ans = 0;
	for(int j = 0; j <= n; ++j) {
		ans = max(ans, dp[n][j]);
	}
	cout << ans << '\n';
	return 0;
}
