def d(u)(u.combination(2).map{|i,j|(@d[i][0]-@d[j][0])**2+(@d[i][1]-@d[j][1])**2<(@d[i][2]+@d[j][2])**2?i:-1}-[-1]).uniq.combination(2).map{|i,j|@d[i][3]==@d[j][3]?2+d(u-[i,j]):0}.max||0
end
while(@d=[];gets.to_i.times{@d<<gets.split.map(&:to_i)})>0
p d(Array 0...@d.size)
end