#include using namespace std; typedef long long ll; typedef pair pll; #define pb push_back #define range(i,a,b) for(int i=(a);i<(b);++i) #define rep(i,n) range(i,0,n) #define dump(x) cerr << #x << " = " << (x) << endl; #define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl; ll extgcd(ll a,ll b,ll& x, ll& y) { if(b==0) return x=1,y=0,a; ll g=extgcd(b,a%b,y,x); y-=a/b*x; return g; } ll modinv(ll a,ll b){ ll res,dummy; extgcd(a,b,res,dummy); if(res<0) res+=b, dummy-=a; return res; } const ll mod=1000000007; ll chinese_remainder(vector b,vector m){ int n=m.size(); set P; rep(i,n){ ll cur=m[i]; for(ll f=2;f*f<=cur;++f){ if(cur%f) continue; while(cur%f==0) cur/=f; P.insert(f); } if(cur>1) P.insert(cur); } vector factor(n); for(auto &prime:P){ int index=0; rep(i,n){ factor[i]=1LL; ll cur=m[i]; while(cur%prime==0) factor[i]*=prime,cur/=prime; if(factor[i]>factor[index]) index=i; } rep(i,n)if(i!=index){ if(factor[i]==1) continue; if(b[index]%factor[i]!=b[i]%factor[i]) return -1; m[i]/=factor[i],b[i]%=m[i]; } } vector constant(n,0LL),coef(n,1LL),v(n,0LL); rep(i,n){ v[i]=(b[i]-constant[i]+m[i])%m[i]; v[i]=(v[i]*modinv(coef[i],m[i]))%m[i]; range(j,i+1,n){ constant[j]=(constant[j]+v[i]*coef[j])%m[j]; coef[j]=(coef[j]*m[i])%m[j]; } } ll ans=0LL; for(int i=n-1;i>=0;--i) ans=(ans*m[i]+v[i])%mod; return ans; } int main(void){ int N; cin >> N; vector X(N),Y(N); rep(i,N) cin >> X[i] >> Y[i]; int zero=0; rep(i,N) zero+=(X[i]==0); if(zero==N){ rep(i,N)rep(j,i) Y[i]/=__gcd(Y[i],Y[j]); ll ans=1LL; rep(i,N) ans=(ans*Y[i])%mod; cout << ans << endl; }else{ cout << chinese_remainder(X,Y) << endl; } return 0; }