import sys input = lambda :sys.stdin.readline()[:-1] ni = lambda :int(input()) na = lambda :list(map(int,input().split())) yes = lambda :print("yes");Yes = lambda :print("Yes");YES = lambda : print("YES") no = lambda :print("no");No = lambda :print("No");NO = lambda : print("NO") ####################################################################### def norm(a): return a[0]*a[0]+a[1]*a[1] def round(a, b): return (a*2+b)//(2*b) def div(a, b): c = (round(a[0]*b[0] + a[1]*b[1], norm(b)), round(a[1]*b[0]-a[0]*b[1], norm(b))) return a[0] - b[0]*c[0] + b[1]*c[1], a[1] - b[0]*c[1] - b[1]*c[0] def gcd(a, b): if b == (0,0): return a return gcd(b, div(a, b)) p, q = na() if p == 0 and q == 0: n = ni() ans = 0 for i in range(n): x, y = na() if x == 0 and y == 0: ans += 1 print(ans) exit() r = gcd((p, q), (p, -q)) n = ni() ans = 0 for _ in range(n): x, y = na() if (r[0] * x + r[1] * y) % norm(r) == 0 and (r[0] * y - r[1] * x) % norm(r) == 0: ans += 1 print(ans)