#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<int> vi; typedef vector<ll> vl; typedef complex<double> P; typedef pair<int,int> pii; #define REP(i,n) for(ll i=0;i<n;++i) #define REPR(i,n) for(ll i=1;i<n;++i) #define FOR(i,a,b) for(ll i=a;i<b;++i) #define DEBUG(x) cout<<#x<<": "<<x<<endl #define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl #define ALL(a) (a).begin(),(a).end() #define MOD (ll)(1e9+7) #define ADD(a,b) a=((a)+(b))%MOD #define FIX(a) ((a)%MOD+MOD)%MOD int main(){ ll p,q; ll n; cin>>p>>q>>n; if(p>q)swap(p,q); ll g = __gcd(p,q); ll sa; if(g!=0)sa = (q-p)/g; ll result = 0; REP(i,n){ ll x,y; cin >> x >> y; x = abs(x); y = abs(y); if(p==0 && q==0){ if(x==0 && y==0)++result; }else if(p==0){ if(x%q==0 && y%q==0)++result; }else{ if(x%g!=0 || y%g!=0)continue; x/=g; y/=g; if(sa%2==1)++result; else{ if((x+y)%2==0)++result; } } } cout << result << endl; return 0; }