#include #define rep(i,n) for(int i=0;i<(n);i++) using namespace std; int main(){ int p,q,n; scanf("%d%d%d",&p,&q,&n); int g=gcd(p,q); int p2=p/g,q2=q/g; int ans=0; rep(_,n){ int x,y; scanf("%d%d",&x,&y); x=abs(x); y=abs(y); if(p==0 && q==0){ if(x==0 && y==0) ans++; continue; } if(x%g!=0 || y%g!=0) continue; x/=g; y/=g; if((p2+q2)%2==1 || (x+y)%2==0) ans++; } printf("%d\n",ans); return 0; }