n = int(input())
a = [int(i) for i in input().split()]
for i in range(n):
    a[i] = (a[i], i+1)
a.sort(reverse=True, key=lambda x: x[0])

dp = [[0]*(n+1) for _ in range(n+1)]

for i in range(1, n+1):
    ans = 0
    for x in range(i+1):
        y = i-x
        activity = a[i-1][0]
        ind = a[i-1][1]
        val1, val2 = 0, 0
        if y-1 >= 0:
            val1 = dp[x][y-1] + activity*(abs(n-(y-1)-ind))
        if x-1 >= 0:
            val2 = dp[x-1][y] + activity*(abs(ind-x))
        dp[x][y] = max(val1, val2)
        if i == n and dp[x][y] > ans:
            ans = dp[x][y]

print(ans)