N=int(input())
A=list(map(int,input().split()))

P=[None]*N
H=list(range(N))

S=0
for i in range(N):
    if i%2:
        x=N-1-(i//2)
    else:
        x=i//2

    C=0
    L=[]
    M=-1
    for j in H:
        e=A[j]*abs(x-j)
        if M<e:
            M=e
            L=[j]
            C=1
        elif M==e:
            L.append(j)
            C+=1

    if i%2:
        u=L[(len(L)-1)//2]
    else:
        u=L[len(L)//2]
    P[x]=u+1
    H.remove(u)
    S+=M

print(S)
