#define _USE_MATH_DEFINES #include "bits/stdc++.h" using namespace std; #define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i)) #define rep(i,j) FOR(i,0,j) #define each(x,y) for(auto &(x):(y)) #define mp make_pair #define MT make_tuple #define all(x) (x).begin(),(x).end() #define debug(x) cout<<#x<<": "<<(x)<; using vi = vector; using vll = vector; long long gcd(long long a, long long b) { return b ? gcd(b, a%b) : a; } void solve() { ll a, b, c, d, N; cin >> a >> b >> c >> d >> N; ll m = abs(a*d - b*c); using T = tuple; set S; ll g1 = gcd(a, c), g2 = gcd(b, d); rep(i, N) { ll x, y; cin >> x >> y; ll z = d * x - c * y; ll w = b * x - a * y; if (m) { z = (z%m + m) % m; w = (w%m + m) % m; } ll xx = g1 ? x % g1 : x; ll yy = g2 ? y % g2 : y; S.insert(T(xx,yy,z,w)); } cout << sz(S) << endl; } int main() { ios::sync_with_stdio(false); cin.tie(0); cout << fixed << setprecision(15); solve(); return 0; }