#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>
#include <algorithm>
#define _USE_MATH_DEFINES
#include<math.h>
#include<sstream>
# include<set>
#define in(n, m) for (ll i=n; i<m;i++)
#define inj(n, m)for (ll j=n; j<m;j++)
#define ink(n, m)for (ll k=n; k<m;k++)
using namespace std;
using ll=long long;
const ll N=2000;
ll dp[2000][2000];
vector <pair<ll,ll>> A(N);
const ll INF = 1LL << 60;


int main() {
	ll N;
	cin >> N;
	in(1, N+1) {
		ll a;
		cin >> a;
		A.push_back(make_pair(a,i));
	}
	
	sort(A.begin(), A.end(),greater<ll>());
	in(1, N + 1) { inj(1, N + 1) { dp[i][j] = -INF; } }
	dp[0][0] = 0;

	in(1, N + 1) {
		ll k = A[i].first, r = A[i].second;
		inj(0, i + 1) {
			dp[j + 1][i - j] = max(dp[j + 1][i - j], dp[j][i - j] + abs(r - j) * k);
			dp[j][i - j + 1] = max(dp[j][i - j + 1], dp[j][i - j] + abs(r - (N - i + j - 1)) * k);

		}

	}
	
	ll ans = 0;
	in(1, N + 1) ans = max(ans, dp[i][N - i]);
	cout << ans << endl;
	return 0;
}