from collections import defaultdict

n = int(input())
arr = map(int, input().split())
arr = tuple(sorted(enumerate(arr), key=lambda tpl: -tpl[1]))

dp = defaultdict(int)
for i, (p, a) in enumerate(arr):
  for l in range(i + 1):
    dp[i + 1, l] = max(dp[i + 1, l], dp[i, l] + a * abs(p - (n - (i - l) - 1)))
    dp[i + 1, l + 1] = max(dp[i + 1, l + 1], dp[i, l] + a * abs(p - l))

print(max([dp[n, i] for i in range(n + 1)]))
