N = int(input())

A = [int(i) for i in input().split()]
left_index = 0
right_index = N-1

ans = 0

for i in range(N):
  update_num = 0
  max_num_index = -1
  for j in range(N):
    alpha = A[j] * max(abs(left_index-j),abs(right_index-j))
    if alpha >= update_num:
      update_num = alpha
      max_num_index = j
  if abs(left_index-max_num_index) > abs(right_index-max_num_index):
    left_index += 1
  else:
    right_index -= 1
  ans += update_num
  A[max_num_index] = -1


print(ans)
