while n = STDIN.gets.chomp.to_i
  if n == 0 then break end
  sum=0
  max_sum=-999999999
  n.times do
    a = STDIN.gets.chomp.to_i
    sum += a
    if max_sum < sum then
      max_sum = sum
    end
  end
  puts max_sum
end