n = int(input())
ass = list(map(int, input().split()))

scores = [[0 for _ in range(n)] for _ in range(n)] # score[index][baby_id]

for baby_id in range(n):
  for index in range(n):
    scores[index][baby_id] = ass[baby_id]*abs(index - baby_id)
 
predic = {():0}
for index in range(n):
  dic = {}
  for i in range(n):
    for key in predic.keys():
      if i in key:
        continue
      else:
        nkey = tuple(sorted(list(key) + [i]))
        if nkey not in dic:
          dic[nkey] = predic[key] + scores[index][i]
        else:
          if dic[nkey] < predic[key] + scores[index][i]:
            dic[nkey] = predic[key] + scores[index][i]
  predic = dic
print(dic[tuple([i for i in range(n)])])  