a,b=gets.split.map(&:to_i).sort if b==0 p 0 else raise g=a.gcd b a/=g b/=g gets;p $<.count{|e| x,y=e.split.map{|e|e.to_i.abs}.sort next if x%g!=0 || y%g!=0 x/=g y/=g y%(b-a)==0 && x%(b-a)==0 } end