#include #include #include #include //#include #include #include #include #include #include //#include #include #include #include //#include #include #include //#include #include #include #include #include const int dx[] = {1, 0, -1, 0}; const int dy[] = {0, 1, 0, -1}; using namespace std; typedef long long ll; typedef vector vi; typedef vector vll; typedef pair pii; // extgcd ll extgcd(ll a, ll b, ll& x, ll& y) { if (a < b) swap(a, b); ll d = a; if (b != 0) { d = extgcd(b, a % b, y, x); y -= (a / b) * x; } else { x = 1; y = 0; } return d; } int main() { cin.tie(0); ios::sync_with_stdio(false); ll P, Q, X, Y; cin >> P >> Q; ll G = extgcd(P, Q, X, Y); int N; cin >> N; int ans = 0; for (int i = 0; i < N; i++) { ll x, y; cin >> x >> y; if (G == 0) { if (x==0 && y==0) ans++; continue; } if (x%G!=0 || y%G!=0) continue; ll a = (x/G)*X, b = (x/G)*Y; ll c = (y/G)*X, d = (y/G)*Y; bool ok = false; for (int j = 0; j < 2; j++) for (int k = 0; k < 2; k++) { ll na = a+j*(Q/G), nb = b-j*(P/G); ll nc = c+k*(Q/G), nd = d-k*(P/G); na = abs(na%2), nb = abs(nb%2); nc = abs(nc%2), nd = abs(nd%2); ok |= (na==nd && nb==nc); } if (ok) ans++; } cout << ans << endl; return 0; }