#At Coder E: Active Infants

import random
N = 10
A = [random.randrange(1,10) for n in range(N)]

f = [n for n in range(N)]
ans = 0

for n in range(N):
    a = sA.pop()
    print(a,sA)
    i = A.index(a)
    if i - f[0] > f[-1] - i:
        ans += (i-f.pop(0)) * a
    else:
        ans += (f.pop()-i) * a

print(ans)
    
        