#include #include #include #include #include #include #include #include using namespace std; int p = 1000000007; #define int long long #define vel vector #define vvel vector #define rep(i,n) for(long long i=0;i #define V vector #define Endl endl #define veb vector #define sq(a) (a)*(a) #define rev(s) reverse(s.begin(),s.end()) #define end_program(s) cout << s < q; q.push(mid1); while (!q.empty()) { int st = q.front(); q.pop(); rep(i, way[st].size()) { int to = way[st][i]; if (dist[to] == -1) { dist[to] = dist[st] + 1; q.push(to); } } } return dist; } pin most_far(int now, int n, vvel &way) { vel dist1 = dis(now, way); pin ans = mkp(-1, 0); rep(i, n) { if (dist1[i] > ans.first) { ans = mkp(dist1[i], i); } } return ans; } int gcd(int a, int b) { a = abs(a); b = abs(b); if (a < b) { swap(a, b); } if (b == 0) { return a; } return gcd(b, a%b); } int per(int a, int b) { int ans = a % b; if (ans < 0) { ans += b; } return ans; } V uni(V &v) { sor(v); V ans(1, v[0]); for (int i = 1; i < v.size(); i++) { if (v[i] != v[i-1]) { ans.push_back(v[i]); } } v = ans; return v; } signed main() { int a, b, c, d; cin >> a >> b >> c >> d; if (a*d - b * c == 0) { int gcd0 = gcd(a, b); int pa =a/ gcd0; int pb =b/ gcd0; int g1; if (pa != 0) { g1 = c / pa; } else { g1 = d / pb; } a = pa*gcd(gcd0, g1); b = pb*gcd(gcd0, g1); if (a < 0) { a *= -1; b *= -1; } int n; cin >> n; V ans(n); if (a != 0) { rep(i, n) { int x, y; cin >> x >> y; int ex = per(x, a); int ey = y-((x - ex)/ a)*b; ans.push_back(mkp(ex, ey)); } } else { swap(a, b); rep(i, n) { int x, y; cin >> y >> x; int ex = per(x, a); int ey = y - ((x - ex) / a)*b; ans.push_back(mkp(ex, ey)); } } uni(ans); cout << ans.size() << Endl; } else { int det = a * d - b * c; det = abs(det); int n; cin >> n; V ans(n); rep(i, n) { int x, y; cin >> x >> y; int nx = d * x - c * y; nx = per(nx, det); int ny = a * y - b * x; ny = per(ny, det); ans.push_back(mkp(nx, ny)); } uni(ans); cout << ans.size() << Endl; } return 0; }