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

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

print(max(scores))