while n = gets.to_i
  break if n <= 0

  sum = 0
  max_num = 0
  n.times do
    tmp = gets.to_i

    sum += tmp
    if sum <= -1
      sum = 0
      next
    end
    max_num = sum if max_num < sum
  end
  puts max_num
end