#include <stdio.h>
#include <algorithm>
long long n, m, x, ans;
long long a[2000];
long long dp[2001];
long long e[2001];
int main() {
	scanf("%lld", &n);
	for (long long i = 0; i < n; i++) {
		scanf("%lld", a + i);
		a[i] = a[i] * 10000 + i;
	}
	std::sort(a, a + n);
	for (long long i = n - 1; i >= 0; i--) {
		for (long long j = 0; j <= m; j++) {
			x = a[i] / 10000 * (a[i] % 10000 - j);
			if (e[j + 1] < x + dp[j])e[j + 1] = x + dp[j];
			x = a[i] / 10000 * (n - 1 - m + j - a[i] % 10000);
			if (e[j] < x + dp[j])e[j] = x + dp[j];
		}
		for (long long j = 0; j <= m + 1; j++) {
			dp[j] = e[j];
			e[j] = 0;
		}
		m++;
	}
	for (long long i = 0; i <= n; i++) {
		if (dp[i] > ans)ans = dp[i];
	}
	printf("%lld\n", ans);
}