// see also: SRM 564 Div2 Hard KnightCircuit  / ナイトツアー
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <complex>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <iomanip>
#include <assert.h>
#include <array>
#include <cstdio>
#include <cstring>
#include <random>
#include <functional>
#include <numeric>
#include <bitset>

using namespace std;

#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a, 0, sizeof a)
#define minus(a) memset(a, -1, sizeof a)
#define minimize(a, x) a = std::min(a, x)
#define maximize(a, x) a = std::max(a, x)

template<class T> constexpr bool in_range(T y, T x, T H, T W) { return -H<=y&&y<H&&-W<=x&&x<W; }

typedef long long ll;
int const inf = 1<<29;

int main() {

  ll p, q; cin >> p >> q;
  ll g = 1;
  if(p > 0 && q > 0) {
    g = __gcd(p, q);
  }

  int ans = 0;
  int N; cin >> N;

  rep(i, N) {

    ll x, y; cin >> x >> y;

    if(x % g == 0);else continue;
    if(y % g == 0);else continue;

    x /= g, y /= g;

    if(p == 0 && q == 0) { ans += x == 0 && y == 0; }
    else if((p + q) % 2) {
      ans ++;
    }
    else if((x + y) % 2 == 0) {
      ans ++;
    }

  }

  cout << ans << endl;

  return 0;
}