// #define DEBUGGING #include using namespace std; #define endl '\n' #define ALL(V) (V).begin(), (V).end() #define ALLR(V) (V).rbegin(), (V).rend() template using V = vector; template using VV = V>; template using P = pair; using ll = int64_t; using ull = uint64_t; using PLL = P; template const T& var_min(const T &t) { return t; } template const T& var_max(const T &t) { return t; } template const T& var_min(const T &t, const Tail&... tail) { return min(t, var_min(tail...)); } template const T& var_max(const T &t, const Tail&... tail) { return max(t, var_max(tail...)); } template void chmin(T &t, const Tail&... tail) { t = var_min(t, tail...); } template void chmax(T &t, const Tail&... tail) { t = var_max(t, tail...); } template const T& clamp(const T &t, const T &low, const T &high) { return max(low, min(high, t)); } template void chclamp(T &t, const T &low, const T &high) { t = clamp(t, low, high); } namespace init__ { struct InitIO { InitIO() { cin.tie(nullptr); ios_base::sync_with_stdio(false); cout << fixed << setprecision(30); } } init_io; } #ifdef DEBUGGING #include "../debug.cpp" #else #define DEBUG(...) 0 #define DEBUG_SEPARATOR_LINE 0 #endif template T make_v(T init) { return init; } template auto make_v(T init, size_t s, Tail... tail) { #define rec make_v(init, tail...) return V(s, rec); #undef rec } ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } int main() { ll A, B, C, D; cin >> A >> B >> C >> D; ll det = abs(A * D - B * C); set st; ll N; cin >> N; for(ll i = 0; i < N; i++) { ll x, y; cin >> x >> y; st.emplace(x, y); } if(det == 0) { bool which = (A != C ? A < C : B < D); ll a = which ? A : C; ll b = which ? B : D; do { if(!A + !B + !C + !D < 2) break; if(!max(A, C) + !max(B, D) >= 2) break; bool is_x = (A == 0 && C == 0); ll G = is_x ? gcd(B, D) : gcd(A, C); set cnt; for(auto ele : st) { ll x, y; tie(x, y) = ele; cnt.emplace((is_x ? x : y), (is_x ? y : x) % G); } cout << cnt.size() << endl; return 0; } while(false); set cnt; for(auto ele : st) { ll x, y; tie(x, y) = ele; if(a == 0) cnt.emplace(y % b); else cnt.emplace(a * y - b * x); } cout << cnt.size() << endl; return 0; } set cnt; for(const auto &ele : st) { ll x, y; tie(x, y) = ele; ll mod0 = D * x % det - C * y % det + det; mod0 %= det; ll mod1 = -(B * x % det) + A * y % det + det; mod1 %= det; cnt.emplace(mod0, mod1); } cout << cnt.size() << endl; return 0; }