while gets
	n = $_.to_i
	break if n==0
	sum = 0
	max = max_input = -100001
	n.times do |i|
		m = gets.to_i
		max_input = [max_input,m].max
		sum = [sum+m,0].max
		max = [max,sum].max
	end
	puts max_input < 0 ? max_input : max
end