import itertools
N = int(input())
A = list(map(int,input().split()))
l = [i for i in range(1,N+1)]

s = []
for v in itertools.permutations(l, len(A)):
    n=0
    for i in range(N):
        n += A[i]*abs(i+1-v[i])
    s.append(n)
print(max(s))