#!/usr/bin/ruby 

while (n = STDIN.gets.to_i) != 0
  max = tmp = -10000
  n.times do |i|
    num = STDIN.gets.to_i
    
    tmp = num + tmp
    max = tmp = num if max + num < num
    max = tmp if tmp > max

  end
  puts max
end