
require 'pp'

def gets_num
  $stdin.gets.chomp.to_i
end

loop do
  n = gets_num
  break if n == 0
  list = n.times.map {gets_num}
  max = list[0]
  result = list.reduce(0) {|accum, x|
    max = accum if (max < accum)
    if (x + accum < 0) then 0
    else x + accum end
  }
  max = result if (result > max)
  puts max
end