#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

const int MAX_N = 2005;

int n, a[MAX_N], order[MAX_N];
ll dp[MAX_N][MAX_N];

signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cin >> n;
	for (int i = 1; i <= n; ++i) {
		cin >> a[i];
	}
	iota(order + 1, order + n + 1, 1);
	sort(order + 1, order + n + 1, [&](int i, int j) {
		return a[i] > a[j];
	});
	for (int k = 1; k <= n; ++k) {
		int i = order[k];
		for (int l = 1; l <= k; ++l) {
			int r = n - (k - l);
			dp[k][l + 1] = max(dp[k][l + 1], dp[k - 1][l] + 1ll * a[i] * abs(i - l));
			dp[k][l] = max(dp[k][l], dp[k - 1][l] + 1ll * a[i] * abs(i - r));
		}
	}
	ll ans = 0;
	for (int l = 1; l <= n + 1; ++l) {
		ans = max(ans, dp[n][l]);
	}
	cout << ans << "\n";
	return 0;
}