import itertools
import numpy as np

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

x = np.arange(N)
ys = np.array(list(itertools.permutations(x)))

print(np.max( np.sum(A * np.abs(x-ys),axis=1) ))