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