import itertools 

N = int(input())
A = list(map(int, input().split()))
ureshisa = [
            [A[i] * abs(i-j) for j in range(N)] for i in range(N)
]
maxV = 0
for P in itertools.permutations(list(range(N))):
  maxV = max(maxV, sum([ureshisa[P[i]][i] for i in range(N)]))
print(maxV)