#include using namespace std; template struct ChineseRemainderTheorem { inline T modulo(T x, const T MOD) { if(0 <= x and x < MOD) return x; x %= MOD; if(x < 0) x += MOD; return x; } // gcd(a, b) T exGCD(T a, T b) { T _p, _q; return exGCD(a, b, _p, _q); } // gcd(a, b) // ap + bq = gcd(a, b)を満たす(p, q) T exGCD(T a, T b, T &p, T &q) { if(b == 0) { // gcd(a, b)p + 0q = gcd(a, b) p = 1, q = 0; return a; } T ret = exGCD(b, a % b, q, p); q -= a / b * p; return ret; } // Garnerの前処理(互いに素にする) // lcm(mod) % MOD T normalisation(vector &b, vector &mod, const T MOD = numeric_limits::max()) { for(int i = 0; i < (int)b.size(); ++i) { for(int j = 0; j < i; ++j) { T g = exGCD(mod[i], mod[j]); // 必要十分性の確認 if ((b[i] - b[j]) % g != 0) throw "NOT FOUND"; mod[i] /= g; mod[j] /= g; T gi = exGCD(mod[i], g); T gj = g / gi; // 共通する場合,iの方が指数大 while(true) { T gg = exGCD(gi, gj); if(gg == 1) break; gi *= gg, gj /= gg; } mod[i] *= gi; mod[j] *= gj; b[i] = modulo(b[i], mod[i]); b[j] = modulo(b[j], mod[j]); } } T ret = 1; for(int i = 0; i < (int)b.size(); ++i) { ret *= mod[i]; ret = modulo(ret, MOD); } return ret; } // x ≡ b(mod m)を満たすx(mod M (= lcm m)) T get(vector &b, vector &mod) { // x ≡ 0(mod 1)は全ての整数 T x = 0, MOD = 1; for(int i = 0; i < (int)b.size(); ++i) { T p, _q; T d = exGCD(MOD, mod[i], p, _q); // 必要十分性の確認 if((x - b[i]) % d != 0) throw "NOT FOUND"; // nextMOD = MOD * (mod[i] / d)なので部分的にmodが取れてオーバーフロー回避 x = x - modulo((x - b[i]) / d * p, (mod[i] / d)) * MOD; // lcm(M, m) = M * m / gcd(M, m) MOD = MOD * (mod[i] / d); x = modulo(x, MOD); } return modulo(x, MOD); } T Garner(vector &b, vector &mod, T MOD = numeric_limits::max()) { try { normalisation(b, mod, MOD); } catch(...) { throw "NOT FOUND"; } vector p(b.size()); for(int i = 0; i < (int)b.size(); ++i) { p[i] = b[i] % mod[i]; for(int j = 0; j < i; ++j) { T inv, _tmp; exGCD(mod[j], mod[i], inv, _tmp); inv = modulo(inv, mod[i]); p[i] = (p[i] - p[j]) * inv; p[i] = modulo(p[i], mod[i]); } } // 復元 T ret = 0; for(int i = 0; i < (int)b.size(); ++i) { T tmp = modulo(p[i], MOD); for(int j = 0; j < i; ++j) { tmp *= mod[j]; tmp = modulo(tmp, MOD); } ret += tmp; ret = modulo(ret, MOD); } return ret; } }; int main() { const int MOD = 1e9 + 7; int n; cin >> n; vector x(n), y(n); bool zero = true; for(int i = 0; i < n; ++i) { cin >> x[i] >> y[i]; if(x[i] > 0) zero = false; } ChineseRemainderTheorem crt; if(zero) { cout << crt.normalisation(x, y, MOD) << '\n'; return 0; } try { int64_t ans = crt.Garner(x, y, MOD); cout << ans << '\n'; } catch(...) { cout << -1 << '\n'; } return 0; }