#  入力
N = int(input())
A = [int(x) for x in input().split()]
 
# 初期化
dp = [[0] * (N+1) for _ in range(N+1)]
dp[0][0] = 0
 
for i in range(0,N):
 
    # 最も嬉しさの高い子供から場所を選択していく
    id = A.index(max(A))
    
    for x in range(0,i+1):
        y = i - x
        
        dp[x+1][y] = max(dp[x+1][y], dp[x][y] + A[id] * (id - x))
        dp[x][y+1] = max(dp[x][y+1], dp[x][y] + A[id] * (((N-1)-y) - id))
        
    A[id] = 0

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