import math
P,Q=map(int,input().split())
N=int(input())
res=0
if P+Q==0:
    for i in range(N):
        X,Y=map(int,input().split())
        if X==0 and Y==0:
            res+=1
    print(res)
    exit()
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)