N = int(input())
A = list(map(int,input().split()))

pos = [i for i in range(N)]
ls = [[i,j] for (i,j) in zip(A,pos)]

ans = 0

import itertools
for v in itertools.permutations(ls):
    count = 0
    for i in range(N):
        count += v[i][0]*abs(v[i][1]-i)
    if ans < count:
        ans = count



print(ans)
