#S = input()
#S1, S2 = input().split()
N = int(input())
#I, K, N  = map(int, input().split())
AA = list(map(int, input().split()))

#D1 = []
#D2 = [[]] * 4
#D1 = [0] * 5
#D2 = [[0] * 5 for i in range(4)]
#D3 = [[[0] * 5 for i in range(4)] for i in range(3)]

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

A = []
for i in range(N):
  A += [[AA[i], i]]
A.sort(reverse=True, key=lambda x:x[0])

mx=0
for i in range(N):
  for pl in range(i+1):
    pr = i - pl
    al = abs(A[i][1]-pl)*A[i][0]
    ar = abs((N-1-pr)-A[i][1])*A[i][0]
    dp[pl][pr+1] = max( dp[pl][pr+1],dp[pl][pr] + ar )
    dp[pl+1][pr] = max( dp[pl+1][pr],dp[pl][pr] + al )
    mx = max(mx,dp[pl][pr+1],dp[pl+1][pr])

print(mx)
