while line = gets.chomp
  break if line == "0"
  ary = []
  max = -100001
  line.to_i.times do
    n = gets.to_i
    ary << 0
    ary.map!{|v| v + n}
    max_temp = ary.max
    max = max_temp if max_temp > max
  end
  puts max
end