p, q = gets.split.map(&:to_i).map(&:abs) if [p,q]==[0,0] type = 0 else gcd = p.gcd(q) p /= gcd; q /= gcd type = (p*q).odd? ? 1 : 2 end puts gets.to_i.times.count{ x, y = gets.split.map(&:to_i).map(&:abs) if type == 0 next [x,y]==[0,0] else next false if x % gcd != 0 || y % gcd != 0 x /= gcd; y /= gcd case type when 1 next (x+y).even? when 2 next true end end }