N = int(input())
l = list(map(int, input().split()))
s = 0
for i in range(int(N/2)):
    d = 0
    b = N
    for j in range(N):
        if l[j]*abs(i-j) >= d:
            d = l[j]*abs(i-j)
            b = j
    s += d
    l[b]= 0
    d = 0
    b = N
    for j in range(N):
        if l[j]*abs(N-1-i-j) >= d:
            d = l[j]*abs(N-1-i-j)
            b = j
    s += d
    l[b]= 0
if N%2 == 1:
    d = 0
    b = N
    for j in range(N):
        if l[j]*abs(int((N-1)/2)-j) >= d:
            d = l[j]*abs(int((N-1)/2)-j)
            b = j
    s += d
print(s)
