import itertools
N = int(input())
A = list(map(int, input().split()))
B = [n for n in range(N)]
mx = 0
for v in itertools.permutations(B, N):
    P = list(v)
    t = 0
    for i in range(N):
        idx = P.index(i)
        t += A[i] * abs(idx-i)
    mx = max([t,mx])
print(mx)