from math import gcd P,Q=map(int, input().split()) if P>Q: P,Q=Q,P g=gcd(P,Q) N=int(input()) cnt=0 if P!=0 and Q!=0: P//=g Q//=g for _ in range(N): x,y=map(int, input().split()) if x%g==0 and y%g==0: x//=g y//=g if (x+y)%2==0 or P*Q%2==0: cnt+=1 elif P==0 and Q!=0: for _ in range(N): x,y=map(int, input().split()) if x%Q==0 and y%Q==0: cnt+=1 else: for _ in range(N): x,y=map(int, input().split()) if x==0 and y==0: cnt+=1 print(cnt)