n=int(input())
D=[int(i) for i in input().split()]
D=[(D[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)}

ymax=n-1
for i in range(n):
    genki=D[i][0]
    posit=D[i][1]
    for p in range(i+1):
        x=i-p
        y=p
        now=dp[(x,y)]
        dp[(x+1,y)]=max(now+genki*abs(x-posit),dp[(x+1,y)])
        dp[(x,y+1)]=max(now+genki*abs(ymax-y-posit),dp[(x,y+1)])

ans=0
for p in range(n+1):
    x=n-p
    y=p
    ans=max(ans,dp[(x,y)])
print(ans)
