#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define popcount __builtin_popcount using namespace std; typedef long long int ll; typedef pair P; void extgcd(ll& a, ll& b, ll& c, ll& d){ if(b==0) return; ll q=d/b; c-=a*q, d-=b*q; swap(a, c), swap(b, d); extgcd(a, b, c, d); } ll a, b, c, d; int solve(){ extgcd(a, b, c, d); if(a<=0) a=-a; c%=a; int n; cin>>n; set

st; for(int i=0; i>x>>y; ll q=y/d; x-=q*c, y-=q*d; x=(x%a+a)%a; st.insert(P(x, y)); } return st.size(); } int solve0(){ bool sw=0; if(b==0 && d==0){ swap(a, b), swap(c, d); sw=1; } extgcd(a, b, c, d); ll p=c, q=d; int n; cin>>n; set

st; for(int i=0; i>x>>y; if(sw) swap(x, y); ll t=y/q; x-=t*p, y-=t*q; st.insert(P(x, y)); } return st.size(); } int main() { cin>>a>>b>>c>>d; if(a*d-b*c==0){ cout<