import itertools

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

def happy(A, order):
    s = 0
    for i in range(N):
        s += A[i] * abs(order[i]-i)
    return s

a = []
for i in range(N):
    a.append(i)

orders = list(itertools.permutations(a,N))

happies = []

for o in orders:
    happies.append(happy(A,o))

happies.sort()

print(happies[len(happies)-1])