import itertools

n = int(input())
arr = tuple(map(int, input().split()))

results = []
for dst in itertools.permutations(range(n)):
  results.append(sum(
    [a * abs(i - dst[i]) for i, a in enumerate(arr)]
  ))

print(max(results))
