import sys
import numpy as np

from itertools import permutations
int1 = lambda x: int(x) - 1
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(500000)

N = int(readline())
A = list(map(int, readline().split()))

init = np.array([i for i in range(N)])

ans = 0

for v in permutations(init):
    diff = abs(init - np.array(v))

    acc = (A * diff).sum()

    ans = max(ans, acc)

print(ans)
