while (n = gets.to_i) != 0
  max = 0
  temp = 0
  n.times do
    a = gets.to_i
    if temp + a > 0
      temp += a
      if temp > max
        max = temp
      end
    else
      temp = 0
    end
  end
  puts max
end