#include #include #include #include using lint = long long; void solve() { lint a, b, c, d; std::cin >> a >> b >> c >> d; int n; std::cin >> n; std::vector> ps(n); for (auto& p : ps) std::cin >> p.first >> p.second; lint det = std::abs(a * d - b * c); if (det != 0) { std::set> ss; for (auto p : ps) { lint x = d * p.first - c * p.second, y = -b * p.first + a * p.second; ss.emplace((x % det + det) % det, (y % det + det) % det); } std::cout << ss.size() << "\n"; } else { lint dx = std::gcd(a, c), dy = std::gcd(b, d); if (dx == 0) { std::swap(dx, dy); for (auto& p : ps) std::swap(p.first, p.second); } std::set> ss; for (auto p : ps) { lint k = p.first / dx; ss.emplace(p.first - k * dx, p.second - k * dy); } std::cout << ss.size() << "\n"; } } int main() { std::cin.tie(nullptr); std::ios::sync_with_stdio(false); solve(); return 0; }