from itertools import permutations
N = int(input())
stuff = list(map(int,input().split()))
#stuff = [5, 5, 6, 1, 1, 1]
junban = list(range(N))

max_happness = 0
for subset in permutations(junban):
    happness = 0
    newjunban = (list(subset))
    for i in range(len(junban)):
        happness +=stuff[i]*abs(newjunban[i]-i)
    if happness>max_happness:
        max_happness = happness
print (max_happness)