#include using namespace std; using i64 = int64_t; using vi = vector; using vvi = vector; int main() { i64 p, q; cin >> p >> q; i64 g = __gcd(p, q); int cnt = 0; int n; cin >> n; for (int i = 0; i < n; i++) { int x, y; cin >> x >> y; if (x % g == 0 && y % g == 0 && ((p + q) / g % 2 == 1 || ((x + y + p + q) / g) % 2 == 0)) { cnt++; } } cout << cnt << endl; }