# My Answer -> TLE
N = int(input())
A = list(map(int, input().split()))

from itertools import permutations

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

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

print(max(scores))