while n = gets.to_i
  break if n == 0
  min = 0
  a_max = -1.0 / 0.0 
  sum = 0
  d = []
  n.times{
    a = gets.to_i
    a_max = a if a_max < a
    sum += a
    min = sum if min > sum
    d << sum - min
  }
  if a_max < 0
    puts a_max
  else
    puts d.max
  end
end