#include using namespace std; using ld = long double; int main(){ cin.tie(nullptr); ios::sync_with_stdio(false); int k; cin >> k; vector> N(k); ld lgN = 0; for(auto& [p, e] : N){ cin >> p >> e; lgN += logl(p) * e; } const int P = N.back().first; ld lg = 0, err = INFINITY; int R; for(int i = 0; i < P / 2; i++){ lg += logl(P - i) - logl(i + 1); if(err > abs(lgN - lg)){ err = abs(lgN - lg); R = i + 1; } } for(auto [p, e] : N){ auto f = [p = p](int x){ int ans = 0; while(1){ x /= p; if(x == 0) return ans; ans += x; } }; if(e != f(P) - f(R) - f(P - R)){ cout << "-1 -1" << endl; return 0; } } cout << P << ' ' << R << endl; }