from queue import Queue P,Q = list(map(int, input().split(' '))) N = int(input()) children = {} for i in range(N): x,y = list(map(int, input().split(' '))) if x not in children: children[x] = [y] else: children[x].append(y) dx = [P, Q, -P, -Q, P, Q, -P, -Q] dy = [Q, P, -Q, -P, -Q, -P, Q, P] history = {} count = 0 que = Queue() que.put((0,0)) while not que.empty(): if count == N: break x,y = que.get() for i in range(len(dx)): nx = x + dx[i] ny = y + dy[i] if nx not in history or ny not in history[nx]: if nx in children and ny in children[nx]: count = count + 1 que.put((nx,ny)) if nx not in history: history[nx] = [ny] else: history[nx].append(ny) print(count)