N=int(input())
*A,=map(int,input().split())
ans=0
L=0
R=N-1
Siz=N-1

h=0
while h<=N-1:
    i=0
    B=[[0]]*N
    while i<=N-1:
        if i-L>=R-i:
            B[i]=[A[i]*(i-L),L,i]
        else:
            B[i]=[A[i]*(R-i),R,i]
        i+=1

    B=sorted(B)
    ans+=B[-1][0]
    if B[-1][1]==L:
        L+=1
    else:
        R-=1
    A[B[-1][2]]=0
    h+=1

print(ans)