import sys import math def main(): input = sys.stdin.read().split() idx = 0 P = int(input[idx]); idx +=1 Q = int(input[idx]); idx +=1 N = int(input[idx]); idx +=1 points = [] for _ in range(N): x = int(input[idx]); idx +=1 y = int(input[idx]); idx +=1 points.append((x, y)) count = 0 if P == 0 and Q == 0: for x, y in points: if x == 0 and y == 0: count +=1 print(count) return # Compute d = gcd(P, Q) d = math.gcd(P, Q) # Compute g = gcd(P+Q, P-Q) a = P + Q b = P - Q g = math.gcd(abs(a), abs(b)) for x, y in points: # Check if x and y are multiples of d if x % d != 0 or y % d != 0: continue # Check sum and difference s = x + y t = x - y if s % g != 0 or t % g != 0: continue count +=1 print(count) if __name__ == "__main__": main()