while true
  n = gets.to_i
  if n == 0
    break
  end
  a = Array.new(n)
  for i in 0..n-1
    a[i] = gets.to_i
  end
  max = a[0]
  sum = Array.new(n)
  sum[0] = [a[0],1] # sum[i][1] includes a[i] and sum[i][0] does not
  for i in 1..n-1
    if a[i] <= 0
      sum[i] = [sum[i-1][0],0]
    elsif sum[i-1][1] == 1
      sum[i] = [sum[i-1][0]+a[i],1]
    elsif a[i] > sum[i-1][0]
      sum[i] = [a[i],1]
    else
      sum[i] = [sum[i-1][0],0]
    end
    if sum[i][0] > max
      max = sum[i][0]
    end
  end
  puts max
end