from itertools import permutations
import numpy as np
N = int(input())
stuff = np.array(list(map(int,input().split())))
#N = 6
#stuff = np.array([5, 5, 6, 1, 1, 1])
junban = np.array(range(N))
max_happness = 0
for subset in permutations(junban):
    happness = 0
    newjunban = np.array((subset))
#    for i in range(N):
#        happness +=stuff[i]*abs(newjunban[i]-i)
    happness = np.dot(stuff, abs(newjunban-junban))
    if happness>max_happness:
        max_happness = happness
print (max_happness)