N = int(input())
A = list(map(int,input().split()))
count = 0
ans = 0
fa = [n for n in range(N)]
while count < N:
    i = A.index(max(A))
    d = 0
    ra = 0
    for a in fa:
        dd = abs(i -a)
        if dd > d:
            d = dd
            ra = a
    fa.remove(ra)
    ans += d * max(A)
    A[i] = 0
    count += 1
print(ans)