#include <bits/stdc++.h>
using namespace std;
int n;
long long dp[2005][2005];
vector<pair<long long, int> > v;
long long solve(int l, int r)
{
	if (r < l)
		return 0;
	if (dp[l][r] != -1)
		return dp[l][r];
	int i = l + n - r - 1;
	return dp[l][r] = max(v[i].first * abs(v[i].second - l) + solve(l + 1, r), v[i].first * abs(v[i].second - r) + solve(l, r - 1));
}
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);

	cin >> n;
	for (int i = 0; i < n; i++)
	{
		int a;
		cin >> a;
		v.push_back({a, i});
	}
	sort(v.rbegin(), v.rend());
	memset(dp, -1, sizeof(dp));
	cout << solve(0, n - 1) << "\n";
}
