N = int(input())
A = list(map(int,input().split()))
out = 0
l = 0
r = N-1
while True:
    maxP = 0
    for i in range(N):
        P = A[i]*abs(l-i)
        if P > maxP:
            maxP = P
            maxi = i
    A[maxi] = 0
    out += maxP
    l+=1
    if l==r:
        break

    maxP = 0
    for i in range(N):
        P = A[i]*abs(r-i)
        if P > maxP:
            maxP = P
            maxi = i
    A[maxi] = 0
    out += maxP
    r+=-1
    if l==r:
        break
maxP=0
for i in range(N):
    P = A[i]*abs(r-i)
    if P > maxP:
        maxP = P
        maxi = i
A[maxi] = 0
out += maxP

print(out)