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(index, total, left, right):
  if index == len(pos_and_a):
    return total
  past_pos, a = pos_and_a[index]
  dist_left = abs(past_pos - left) 
  dist_right = abs(right - past_pos)
  if dist_left == dist_right:
  	return max(inner(index+1, total + a * dist_left, left+1, right), 
    		   inner(index+1, total + a * dist_right, left, right-1))
  if dist_left > dist_right:
    return inner(index+1, total + a * dist_left, left+1, right)
  return inner(index+1, total + a * dist_right, left, right-1) 

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