N = int(input())
A = list(map(int, input().split()))

A = [(a, i) for i, a in enumerate(A)]
A.sort(reverse = True)

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

ans = 0

for l in range(N):
    for r in range(N):
        if l+r == N:
            ans = max(ans, dp[l][r])
            break
        else:
            a, i = A[l+r]
            dp[l+1][r] = max(dp[l+r][r], dp[l][r] + a*abs(l-i))
            dp[l][r+1] = max(dp[l][r+1], dp[l][r] + a*abs((N-1-r)-i))

print(ans)