import itertools

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

L = [i for i in range(N)]
p = list(itertools.permutations(L))
ans = 0
for i in range(len(p)):
    temp = 0
    for j in range(N):
        temp += A[j]*abs(p[i][j]-j)
    ans = max(ans,temp)
print(ans)