N = int(input())
A = list(map(int,input().split()))

A = [0]+A
DP = [[0]*N for i in range(N+1)]
DPPath = [[[0]*N]*N for i in range(N+1)]

for i in range(1,N+1):
    Ax,x = A[i],i-1
    for y in range(N):
        for b in range(N):
            Path = DPPath[i-1][b][::]
            if Path[y]:continue
            Path[y] = 1
            if DP[i][y] < DP[i-1][b]+Ax*abs(x-y):
                DP[i][y]=DP[i-1][b]+Ax*abs(x-y)
                DPPath[i][y]=Path

print(max(DP[N]))