n = int(input())
a = list(map(int, input().split()))
lst = [i for i in range(n)]
start = 0
end = n-1
max_happy = 0
for _ in range(n):
  m = -1
  for j in lst:
    if abs(j - start) > abs(j - end):
      happy = a[j] * abs(j - start)
      idx = 0
    else:
      happy = a[j] * abs(j - end)
      idx = 1
    if happy > m:
      m = happy
      m_idx = idx
      m_point = j
  max_happy += m
  lst.remove(m_point)
  if m_idx == 0:
    start += 1
  else:
    end -= 1
print(max_happy)
