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

a.sort(reverse=True)
INF = float('inf')
#print(a)

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

for num, (A, pos) in enumerate(a):
    #print("="*5, num, "="*5)
    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番目の時

        # print("="*3, i, "="*3)
        # for k in range(len(dp)):
        #     print(dp[k])
    

ans = 0
for i in range(n+1):
    j = n-i
    ans = max(ans, dp[i][j])
    # print(f"i = {i}")
    # print(f"j = {j}")
    # print(max(ans, dp[i][j]))

print(ans)