n = gets.chomp.split(' ').map(&:to_i)[0]
a = gets.chomp.split(' ').map(&:to_i)

head = 0
tail = n - 1
ans = 0
n.times do
  max = 0
  index = 0
  pos = nil
  
  a.each_with_index do |a_i, i|
    val = (i - head) >= (tail - i) ? a_i * (i - head) : a_i * (tail - i)
  	if(val > max)
      max = val
      index = i
      pos = (i - head) >= (tail - i) ? :head : :tail
    end
  end
  head += 1 if pos == :head
  tail -= 1 if pos == :tail
  a[index] = 0
  ans += max
end

puts ans