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

int n;
long long dp[2001][2001], ans = 0;
vector<pair<int, int>> a;

int main() {
	cin >> n;
	for (int i = 0, m; i < n; i++) {
		cin >> m;
		a.emplace_back(m, i);
	}
	sort(a.begin(), a.end(), greater<pair<int, int>>());

	for (int i = 0; i < n; i++) { //既にi人並んでいる
		for (int j = 0; j < i + 1; j++) { //左からj人並んでいる
			//左側に追加
			dp[i + 1][j + 1] = max(dp[i + 1][j + 1],
					dp[i][j] + (long long) abs(j - a[i].second) * a[i].first);
			//右側に追加
			dp[i + 1][j] = max(dp[i + 1][j],
					dp[i][j]
							+ (long long) abs(n - i + j - 1 - a[i].second)
									* a[i].first);
		}
	}
	for (int i = 0; i <= n; i++) {
		ans = max(ans, dp[n][i]);
	}
	cout << ans << endl;
}
