def maxnumseq( list )
	max = -100000 	

	while list.size > 0
		sum = 0
		list.each{ |n|
			sum += n
			
			if max < sum
				max = sum
			end
			if sum < 0
				break
			end
		}
		list.shift
	end
	return max
end

def main
	answers = Array.new
	while line = $stdin.gets
		n = line.chomp.to_i
		break if n == 0
		
		num_list = Array.new
		n.times{
			num = $stdin.gets.chomp.to_i
			num_list << num
		}
		answers << maxnumseq( num_list )
	end

	answers.each{ |a| puts a }
end

main
