import itertools

N=int(input())
actlist=list(map(int,input().split()))
alllist=list(itertools.permutations(range(1,N+1)))

count=1
l=len(alllist)
maxnum=0

for i in range(0,l-1):
    for j in range(i+1,l):
        hapsum=0
        for m,n in zip(alllist[i],alllist[j]):
            hapsum+=actlist[m-1]*abs(m-n)
        if maxnum<hapsum:
            maxnum=hapsum
        
print(maxnum)