n = int(input())
a = [(A, i) for i, A in enumerate(map(int, input().split()))]
a.sort(reverse=True)

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

for num, (A, pos) in enumerate(a):
    for i in range(num+1):
        j = num - i
        dp[i+1][j] = max(dp[i+1][j], dp[i][j] + A*abs(pos-i))  # 左からi番目の時
        dp[i][j+1] = max(dp[i][j+1], dp[i][j] + A*abs((n-1-j)-pos))  # 右からj番目の時


ans = 0
for i in range(n+1):
    j = n-i
    ans = max(ans, dp[i][j])

print(ans)