N=int(input())
A=list(map(int,input().split()))
ans=0
for k in range(N):
    if k%2==0:
        left=[]
        for j in range(N):
            left.append(A[j]*abs(j-k//2))
        ans+=max(left)
        max_index=left.index(max(left))
        A[max_index]=0
    
    if k%2==1:
        right=[]
        for j in range(N):
            right.append(A[j]*abs(N-1-j-k//2))
        ans+=max(right)
        max_index=right.index(max(right))
        A[max_index]=0
print(ans)


