N=int(input())
A=list(map(int,input().split()))
L=[]
for i in range(N):
    L.append([A[i],i])

def counter(l):
    c=0
    for i in range(N):
        c+=L[i][0]*abs(L[i][1]-i)
    return c

point=0
for i in range(N):
    for j in range(N)[::-1]:
        
        L[i][0],L[j][0]=L[j][0],L[i][0]
        L[i][1],L[j][1]=L[j][1],L[i][1]
        
        p=counter(L)
        if p>point:
            point=p
        else:
            L[i][0],L[j][0]=L[j][0],L[i][0]
            L[i][1],L[j][1]=L[j][1],L[i][1]

print(point)