#include #define rep(i, n) for (int i = 0; i < (n); i++) #define repr(i, n) for (int i = (n) - 1; i >= 0; i--) using namespace std; using ll = long long; int main() { cin.tie(nullptr); ios::sync_with_stdio(false); ll a, b, c, d; cin >> a >> b >> c >> d; /* static bool can[200][200]; queue qy; queue qx; qy.push(100); qx.push(100); auto ins = [&](int x, int y) { if (x < 0 || y < 0 || x >= 200 || y >= 200) return; if (!can[x][y]) { can[x][y] = true; qx.push(x); qy.push(y); } }; while (!qx.empty()) { int x = qx.front(); qx.pop(); int y = qy.front(); qy.pop(); ins(x + a, y + b); ins(x - a, y - b); ins(x + c, y + d); ins(x - c, y - d); } rep(i, 100) { rep(j, 100) { cout << can[i][j]; } cout << endl; } */ set> st; int n; cin >> n; ll det = abs(a * d - b * c); ll gx = __gcd(a, c); ll gy = __gcd(b, d); rep(i, n) { int x, y; cin >> x >> y; if (det != 0) { ll nx = d * x - c * y; ll ny = -b * x + a * y; nx %= det; ny %= det; if (nx < 0) nx += det; if (ny < 0) ny += det; st.emplace(nx, ny); } else if (gx != 0) { st.emplace(-b*x + a*y, x % gx); } else { st.emplace(-b*x + a*y, y % gy); } } cout << st.size() << endl; }