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

import math
from itertools import permutations

lis = [0]*N
for i in range(N):
    lis[i] = i

num = math.factorial(N)

scores = [0] * num
for i, v in enumerate(permutations(lis, N)):
    score = 0
    for j in range(N):
        score += abs(v.index(j)-j) * A[j]
    scores[i] = score

print(max(scores))