import numpy as np
import math
import itertools
n = int(input())
l = list(map(int, input().split()))
ans = 0
pos = [0] * n
for i in range(n):
    pos[i] = list(map(lambda x: abs(x - i), list(range(n))))
pos = np.array(pos)
tot = np.zeros(math.factorial(n))
for i in range(n):
    pos[i, :] = pos[i, :] * l[i]
for i, x in enumerate(itertools.permutations(range(n))):
    tot[i] = np.sum(pos[list(range(n)), x])
print(int(np.max(tot)))
