import math P,Q=map(int,input().split()) if P+Q==0: print(0) exit() N=int(input()) res=0 g=math.gcd(P,Q) P//=g Q//=g for i in range(N): X,Y=map(int,input().split()) X=abs(X) Y=abs(Y) if X%g==0 and Y%g==0: X//=g Y//=g if P%2 and Q%2: if (X+Y)%2==0: res+=1 else: res+=1 print(res)