#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include template inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } const long long MAX = 5100000; const long long INF = 1LL << 60; const long long mod = 1000000007LL; //const long long mod = 998244353LL; using namespace std; typedef unsigned long long ull; typedef long long ll; ll gcd(ll x, ll y) { ll r; if (x < y) { swap(x, y); } while (y > 0) { r = x % y; x = y; y = r; } return x; } long long extGCD(long long a, long long b, long long& x, long long& y) { if (b == 0) { x = 1; y = 0; return a; } long long d = extGCD(b, a % b, y, x); y -= a / b * x; return d; } int main() { /* cin.tie(nullptr); ios::sync_with_stdio(false); */ ll a, b, c, d; cin >> a >> b >> c >> d; ll adbc = llabs(a * d - b * c); ll n; scanf("%lld", &n); ll res = 0; set> s; if (adbc == 0) { vector x(n), y(n); for (ll i = 0; i < n; i++) scanf("%lld %lld", &x[i], &y[i]); if (gcd(a, c) == 0) { swap(a, c); swap(b, d); for (ll i = 0; i < n; i++) swap(x[i], y[i]); } ll e, f; a = extGCD(a, c, e, f); b = b * e + d * f; for (ll i = 0; i < n; i++) { auto p = make_pair(x[i] % a, y[i] - x[i] / a * b); s.insert(p); } } else { for (ll i = 0; i < n; i++) { ll x, y; scanf("%lld %lld", &x, &y); ll r1 = d * x - c * y; ll r2 = -b * x + a * y; r1 %= adbc; r2 %= adbc; if (r1 < 0) r1 += adbc; if (r2 < 0) r2 += adbc; auto p = make_pair(r1, r2); //cout <