N = int(input())
A = list(map(int,input().split()))
out = 0
l = 0
r = N-1
while True:
    maxP1 = 0
    for i in range(N):
        P = A[i]*abs(l-i)
        if P > maxP1:
            maxA1 = A[i]
            maxP1 = P
            maxi1 = i
        if (P!=0)and(P == maxP1):
            if A[i]>maxA1:
                maxA1 = A[i]
                maxP1 = P
                maxi1 = i
    maxP2 = 0
    for i in range(N):
        P = A[i]*abs(r-i)
        if P > maxP2:
            maxA2 = A[i]
            maxP2 = P
            maxi2 = i
        if (P!=0)and(P == maxP2):
            if A[i]>maxA2:
                maxA2 = A[i]
                maxP2 = P
                maxi2 = i
    if maxP1 > maxP2:
        l+=1
        out += maxP1
        A[maxi1] = 0
    elif maxP1 < maxP2:
        r+=-1
        out += maxP2
        A[maxi2] = 0
    elif maxP1 == maxP2:
        if maxA1>maxA2:
            l+=1
            out += maxP1
            A[maxi1] = 0
        else:
            r+=-1
            out += maxP2
            A[maxi2] = 0
    if l==r:
        break

maxP3=0
for i in range(N):
    P = A[i]*abs(r-i)
    if P >= maxP3:
        maxP3 = P
        maxi3 = i
A[maxi3] = 0
out += maxP3

print(out)