N=int(input())
actlist=list(map(int,input().split()))
As = sorted([(A, i) for i, A in enumerate(actlist)])[::-1]

INF = float('inf')
left=1
right=N
maxnum=0

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

dp[0][0]=0
for r in range(N+1):
    for l in range(N-r+1):
        dp[l][r]=max(dp[l][r-1]+As[l+r-1][0]*abs(N-r-As[l+r-1][1]),\
          dp[l-1][r]+As[l+r-1][0]*abs(l-1-As[l+r-1][1]))
        maxnum=dp[l][r] if maxnum<dp[l][r] else maxnum

    
print(maxnum)