#include int p, q, n, x[100000], y[100000]; int gcd(int a, int b) { if(b == 0) { return a; } return gcd(b, a % b); } int main(void) { scanf("%d%d%d", &p, &q, &n); int i; for(i = 0; i < n; i++) { scanf("%d%d", &x[i], &y[i]); } if(p < q) { int temp = p; p = q; q = temp; } int d = gcd(p, q), counter = 0; for(i = 0; i < n; i++) { if(q != 0) { if( x[i] % d == 0 && y[i] % d == 0 && ( ((p + q) / d) % 2 == 1 || ((x[i] + y[i]) / d) % 2 == 0 ) ) { counter++; } } else if(p != 0) { if( x[i] % p == 0 && y[i] % p == 0 ) { counter++; } } else { if( x[i] == 0 && y[i] == 0 ) { counter++; } } } printf("%d\n", counter); return 0; }