import numpy as np

n = int(input())
a = np.array(list(map(int, input().split())))

ans = 0
det = np.ones((n))

if n % 2 == 0:
    p = []
    for i in range(int(n/2)):
        p.append(n-1 - i)
    for i in range(int(n/2)):
        p.append(int(n/2) + i)
else:
    p = [abs(i-int(n/2)) + int(n/2) for i in range(n)]
    
for i in range(n):
    ans += max(a * p)
    hoge = np.argmax(a * p)
    det[hoge] *= 0
    p *= det
    
print(ans)    