n=int(input())
A=[int(i) for i in input().split()]
D=[(A[i],i) for i in range(n)]
D.sort(reverse=True)

dp={(x,y):0 for x in range(0,n+1) for y in range(0,n+1-x)}

for i in range(n):
    for p in range(i+1):
        x=i-p
        y=p
        now=dp[(x,y)]
        x_side=D[i][0]*abs(x-D[i][1])
        y_side=D[i][0]*abs(n-y-1-D[i][1])
        dp[(x+1,y)]=max(now+x_side,dp[(x+1,y)])
        dp[(x,y+1)]=max(now+y_side,dp[(x,y+1)])
    
res=[]
for p in range(n+1):
    x=n-p
    y=p
    res.append(dp[(x,y)])
print(max(res))