include Math
require 'tsort'

loop do
	n = gets.to_i
	break if n == 0
	xs, ys, xt, yt = gets.split.map(&:to_i)
	wall_arrs = [[], []]
	n.times do
		x, y, r = gets.split.map(&:to_i)
		if (x - xs) ** 2 + (y - ys) ** 2 <= r ** 2
			wall_arrs[0] << [x, y, r]
		elsif (x - xt) ** 2 + (y - yt) ** 2 <= r ** 2
			wall_arrs[1] << [x, y, r]
		end
	end

	class Hash
		include TSort
		alias :tsort_each_node :each_key
		def tsort_each_child(i)
			(self[i] || []).each do |j|
				yield j
			end
		end
	end

	sum = 0

	wall_arrs.each do |walls|
		graph = {}
		(0..walls.size-1).to_a.permutation(2) do |i, j|
			x1, y1, r1 = walls[i]
			x2, y2, r2 = walls[j]
			if hypot(x1 - x2, y1 - y2) + r1 <= r2
				(graph[i] ||= []) << j
			end
		end

		ts = graph.tsort
		if !ts.empty?
			depth = Hash.new(0)
			depth[ts[-1]] = 1
			until ts.empty?
				i = ts.pop
				(graph[i] || []).each do |j|
					depth[j] = depth[i] + 1 if depth[i] + 1 > depth[j]
				end
			end
			sum += depth.values.max
		end
	end
	
	p sum
end