#include #include #include #include #include #include #define Max(a, b) ((a) > (b) ? (a) : (b)) #define Min(a, b) ((a) > (b) ? (b) : (a)) #define abs(x) ((x) > 0 ? (x) : -(x)) #define rep(i, n) for(int i = 0; i < (n); i++) #define INF 1000000000000 //10^12 #define MOD 1000000007 //10^9 + 7 #define endl printf("\n") typedef long long ll; typedef struct { ll x, y; } R; //b > 0とする ll rem(ll a, ll b) { if (a < 0 && a % b < 0) return a % b + b; if (b == 0) return a; return a % b; } ll gcd(ll a, ll b) { if (a == 0 || b == 0) return a + b; if (a < b) return gcd(b, a); return gcd(b, a % b); } int Rsort(const void *a, const void *b) { R A = *(R *)a, B = *(R *)b; if (A.x == B.x && A.y == B.y) return 0; if (A.x < B.x) return -1; if (A.x > B.x) return 1; if (A.y < B.y) return -1; return 1; } int main(int argc, char **argv) { ll a, b, c, d; scanf("%lld %lld %lld %lld", &a, &b, &c, &d); int n; scanf("%d", &n); if (a * d - b * c != 0) { ll p = abs(a * d - b * c); ll x, y; R r[100010]; for (int i = 0; i < n; i++) { scanf("%lld %lld", &x, &y); r[i].x = rem(d * x - c * y, p); r[i].y = rem(a * y - b * x, p); } qsort(r, n, sizeof(R), Rsort); int cnt = 1; for (int i = 0; i < n - 1; i++) { if (r[i].x != r[i + 1].x || r[i].y != r[i + 1].y) cnt++; } printf("%d\n", cnt); } else { ll dv, dv2; ll s, t, p, q; if (a != 0) { dv = gcd(a, c); s = abs(a / dv); t = abs(c / dv); p = dv; q = b / (a / dv); } else { dv = gcd(b, d); s = abs(b / dv); t = abs(d / dv); p = a / (b / dv); q = dv; } ll x, y; R r[100010]; ll o; for (int i = 0; i < n; i++) { scanf("%lld %lld", &x, &y); r[i].x = rem(x, p); o = (x - rem(x, p)) / p; r[i].y = y - q * o; } qsort(r, n, sizeof(R), Rsort); int cnt = 1; for (int i = 0; i < n - 1; i++) { if(r[i].x != r[i + 1].x || r[i].y != r[i + 1].y){ cnt++; } } printf("%d\n", cnt); } return 0; }