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