N = int(input())
a_s = map(int, input().split())

left = 0
right = N-1
pos_and_a = list(sorted(enumerate(a_s), key=lambda x: -(x[1] * max(x[0]-left, right-x[0]))))

def inner(pos_and_a, total, left, right):
  if not pos_and_a:
    return total
  pos_and_a = list(sorted(pos_and_a, key=lambda x: -(x[1] * max(x[0]-left, right-x[0]))))
  past_pos, a = pos_and_a[0]
  del pos_and_a[0]
  dist_left = abs(past_pos - left) 
  dist_right = abs(right - past_pos)
  return max(inner(pos_and_a[:], total + a * dist_left, left+1, right), 
             inner(pos_and_a[:], total + a * dist_right, left, right-1))

print(inner(pos_and_a, 0, left, right))