import itertools

#((0, 1), (1, 3), (2, 4), (3, 2))
#((0, 1), (1, 3), (3, 2), (2, 4))
def calc1(target):
  global First
  list = []
  for i in range(len(First)):
    list.append(abs(target.index(First[i]) - i))
  return list

def calc2(ret):
  global First
  sum = 0
  for i in range(len(First)):
    sum += First[i][1] * ret[i]
  return sum

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

M = list(enumerate(A))
#print(M)

L = list(itertools.permutations(M))
#print(L)
First = L[0]

max = 0

for i in range(len(L)):
#  print(calc1(L[i]))
  ret = calc2(calc1(L[i]))
  #print(ret)
  if max < ret:
    max = ret

print(max)
