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

import itertools
list2 = [ perm for perm in itertools.permutations(range(1,N+1))]
res=0
for perm in list2:
    score=0
    #print(perm)
    
    for i in range(len(list1)):
        #print(abs(i+1 - perm[i]))
        score += list1[i] * abs(i+1 - perm[i])
    if score > res:
        res = score
    #print(score)
print(res)