$debug=0
def main
  dat=[]
  fh=STDIN
  #fh=File.new("x.txt", "r")
  while fh.gets
    n=$_.chomp.to_i
    break if n==0

    max= -9999999
    subseq = []

    n.times {
      a = fh.gets.chomp.to_i
      subseq.map!{|x| x+= a}
      subseq.push(a)

      cmax = subseq.max
      max = cmax if cmax > max
    }
    puts max

  end
end

if $0 == __FILE__ then
  main
end
