#include #include #include #include using namespace std; long long gcd(long long x, long long y) { if (y == 0) return x; return gcd(y, x % y); } int main() { cin.tie(0); ios_base::sync_with_stdio(false); long long A, B, C, D; int N; cin >> A >> B >> C >> D >> N; vector X(N), Y(N); for (int i = 0; i < N; ++i) { cin >> X[i] >> Y[i]; } if (B * C - A * D != 0) { set > d; for (int i = 0; i < N; ++i) { long long xc = B * X[i] - A * Y[i]; long long yc = D * X[i] - C * Y[i]; bool xt = false, yt = false; if (xc < 0) xt = true, xc *= -1; xc %= abs(B * C - A * D); if (xt && xc != 0) xc = abs(B * C - A * D) - xc; if (yc < 0) yt = true, yc *= -1; yc %= abs(D * A - C * B); if (yt && yc != 0) yc = abs(D * A - C * B) - yc; d.insert(make_pair(xc, yc)); } cout << d.size() << endl; } else { long long gx = gcd(A, C), gy = gcd(B, D); set d; for (int i = 0; i < N; ++i) { d.insert(gy * X[i] - gx * Y[i]); } cout << d.size() << endl; } return 0; }