import itertools

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

count=1

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

print(maxnum)