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

def f(A,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]
        H.remove(u)
        S+=M
    return S

B=[A[-k] for k in range(1,len(A)+1)]
print(max(f(A,N),f(B,N)))
