Problem:
Sun and Moon
In the year 20XX, mankind is hit by an unprecedented crisis.
The power balance  between the sun and the moon  was broken by the total eclipse of the sun, and the end is looming!
To save the world, the secret society called "Sun and Moon" decided to perform the ritual to balance the power of the sun and the moon called "Ritual of Sun and Moon".
The ritual consists of "Ritual of Sun" and "Ritual of Moon". "Ritual of Moon" is performed after "Ritual of Sun".
A member of the society is  divided into two groups, "Messengers of Sun" and "Messengers of Moon".
Each member has some offerings and magic power.
First, the society performs "Ritual of Sun".
In the ritual, each member sacrifices an offering.
If he can not sacrifice an offering here, he will be killed.
After the sacrifice, his magic power is multiplied by the original number of his offerings.
Each member must perform the sacrifice just once.
Second, the society performs "Ritual of Moon".
In the ritual, each member sacrifices all remaining offerings.
After the sacrifice, his magic power is multiplied by
x
p
.
Here
x
is the number of days from the eclipse (the eclipse is 0th day) and
p
is the number of his sacrificed offerings.
Each member must perform the sacrifice just once.
After two rituals, all "Messengers of Sun" and "Messengers of Moon" give all magic power to the "magical reactor".
If the total power of "Messengers of Sun" and the total power of "Messengers of Moon" are equal,
the society will succeed in the ritual and save the world.
It is very expensive to perform "Ritual of Sun".
It may not be able to perform "Ritual of Sun" because the society is in financial trouble.
Please write a program to calculate the minimum number of days from the eclipse in which the society can succeed in "Ritual of Sun and Moon" whether "Ritual of Sun" can be performed or not.
The society cannot perform the ritual  on the eclipse day (0-th day).
Input
The format of the input is as follows.
N
O
1
P
1
...
O
N
P
N
The first line contains an integer
N
that is the number of  members of the society (
0 ≤ N ≤ 1,000
).
Each of the following
N
lines contains two integers
O
i
(
0 ≤ O
i
≤ 1,000,000,000
) and
P
i
(
1 ≤ |P
i
| ≤ 1,000,000,000,000,000
).
O
i
is the number of the
i
-th member's offerings and
|P
i
|
is the strength of  his magic power.
If
P
i
is a positive integer, the
i
-th member belongs to "Messengers of Sun", otherwise he belongs to "Messengers of Moon".
Output
If  there exists the number of days from the eclipse that satisfies the above condition , print the minimum number of days  preceded by "Yes ".
Otherwise print "No".
Of course, the answer must be a positive integer.
Sample Input 1
9
2 1
1 -1
1 -1
1 -1
1 -1
0 1
0 1
0 1
0 1
Output for the Sample Input 1
Yes 2
Sample Input 2
2
1 1
0 -1
Output for the Sample Input 2
No

Submitted solutions:

code_snippet: #include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <cstdlib>
#include <ctime>
#include <numeric>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    srand((unsigned)time(nullptr));
    int N;
    cin >> N;
    map<ll, ll> polyF;
    for (int i = 0; i < N; i++){
        ll O, P;
        cin >> O >> P;
        polyF[O] += P;
    }
    if(N == 0){
        cout << "Yes 1" << "\n";
        return 0;
    }
    bool allZero = true;
    for(auto &it : polyF){
        if(it.second != 0){
            allZero = false;
            break;
        }
    }
    if(allZero){
        cout << "Yes 1" << "\n";
        return 0;
    }
    ll k = -1;
    for(auto &it : polyF){
        if(it.second != 0){
            k = it.first;
            break;
        }
    }
    if(k < 0) k = 0;
    vector<pair<ll, ll>> polyH;
    for(auto &it : polyF){
        if(it.first >= k)
            polyH.push_back({it.first - k, it.second});
    }
    ll H0 = 0;
    for (size_t i = 0; i < polyH.size(); i++){
        if(polyH[i].first == 0)
            H0 += polyH[i].second;
    }
    ll absH0 = H0 < 0 ? -H0 : H0;
    ull A = (ull)absH0;
    vector<ull> factors;
    if(A > 1){
        ull temp = A;
        for (ull i = 2; i * i <= temp; i++){
            while(temp % i == 0){
                factors.push_back(i);
                temp /= i;
            }
        }
        if(temp > 1)
            factors.push_back(temp);
    }
    if(A <= 1)
        factors.push_back(1);
    map<ull,int> group;
    for (size_t i = 0; i < factors.size(); i++)
        group[factors[i]]++;
    vector<pair<ull,int>> pf;
    for (auto &it : group)
        pf.push_back({it.first, it.second});
    vector<ull> divs;
    divs.push_back(1);
    for (size_t i = 0; i < pf.size(); i++){
        vector<ull> tempDiv;
        for (size_t j = 0; j < divs.size(); j++){
            ull cur = 1;
            for (int cnt = 0; cnt <= pf[i].second; cnt++){
                tempDiv.push_back(divs[j] * cur);
                cur *= pf[i].first;
            }
        }
        divs = tempDiv;
    }
    sort(divs.begin(), divs.end());
    vector<ll> mods;
    mods.push_back(1000000007LL);
    mods.push_back(1000000009LL);
    auto modPow = [&](ll base, ll exp, ll mod) -> ll {
        ll res = 1;
        base %= mod;
        if (base < 0)
            base += mod;
        while (exp){
            if (exp & 1)
                res = ((ull)res * (ull)base) % mod;
            base = ((ull)base * (ull)base) % mod;
            exp >>= 1;
        }
        return res;
    };
    bool found = false;
    ull ans = 0;
    for (size_t i = 0; i < divs.size(); i++){
        if(divs[i] == 0)
            continue;
        bool ok = true;
        for (size_t j = 0; j < mods.size(); j++){
            ll mod = mods[j];
            ll val = 0, der = 0;
            for (size_t t = 0; t < polyH.size(); t++){
                ll exp = polyH[t].first;
                ll coef = polyH[t].second % mod;
                if (coef < 0)
                    coef += mod;
                ll power = modPow((ll)divs[i], exp, mod);
                val = (val + (coef * power) % mod) % mod;
                if (exp > 0){
                    ll power_der = modPow((ll)divs[i], exp - 1, mod);
                    der = (der + ((exp % mod) * (coef % mod)) % mod * power_der) % mod;
                }
            }
            if (val % mod != 0 || der % mod != 0){
                ok = false;
                break;
            }
        }
        if (ok){
            found = true;
            ans = divs[i];
            break;
        }
    }
    if(found)
        cout << "Yes " << ans << "\n";
    else
        cout << "No" << "\n";
    return 0;
}
accuracy: 1
time_ms: 890
memory_kb: 3536
final_rank: 4

code_snippet: #include <bits/stdc++.h>
int main()
{
    using ll = long long;
    int N;
    std::cin >> N;
    std::map<ll, ll> Fs;
    for (int i = 0; i < N; i++) {
        ll o, p;
        std::cin >> o >> p;
        Fs[o] += p;
        if (Fs[o] == 0) { Fs.erase(o); }
    }
    auto sqrt = [&](const ll n) {
        const ll x = (ll)std::sqrt(n) - 100;
        const ll y = (ll)std::sqrt(n) * 2 + 100;
        for (ll i = std::max(0LL, x); i <= y; i++) {
            if (i * i == n) { return i; }
        }
        return -1LL;
    };
    if (Fs.empty()) {
        std::cout << "Yes " << 1 << std::endl;
        return 0;
    }
    const auto A = std::abs(Fs.begin()->second);

    //    std::cerr << A << std::endl;

    std::set<ll> ns;
    for (ll i = 1; i <= 1000000; i++) {
        if (A % (i * i) == 0) { ns.insert(i); }
        if (A % i == 0) {
            const ll B = A / i;
            const ll b = sqrt(B);
            if (b != -1) { ns.insert(b); }
        }
    }
    ns.erase(0);

    // for (const ll n : ns) { std::cerr << n << ","; }
    // std::cerr << std::endl;

    constexpr int MN      = 3;
    constexpr ll mods[MN] = {1000000007, 1000000009, 998244353};
    auto check            = [&](const ll n) {
        for (int i = 0; i < MN; i++) {
            const ll mod = mods[i];
            auto add     = [&](const ll i, const ll j) { return (i + j) % mod; };
            auto mul     = [&](const ll i, const ll j) { return (i * j) % mod; };
            auto pow     = [&](auto self, const ll i, const ll n) -> ll { return n == 0 ? 1 : n % 2 == 0 ? self(self, mul(i, i), n / 2) : mul(self(self, i, n - 1), i); };
            std::map<ll, ll> Gs;
            for (const auto [b, a] : Fs) { Gs[b] = add(a % mod, mod); }

            ll sum = 0;
            for (const auto [b, a] : Gs) { sum = add(sum, mul(a, pow(pow, n, b))); }
            if (sum != 0) { return false; }
        }
        for (int i = 0; i < MN; i++) {
            const ll mod = mods[i];
            auto add     = [&](const ll i, const ll j) { return (i + j) % mod; };
            auto mul     = [&](const ll i, const ll j) { return (i * j) % mod; };
            auto pow     = [&](auto self, const ll i, const ll n) -> ll { return n == 0 ? 1 : n % 2 == 0 ? self(self, mul(i, i), n / 2) : mul(self(self, i, n - 1), i); };
            std::map<ll, ll> Gs;
            for (const auto [b, a] : Fs) {
                if (b == 0) { continue; }
                Gs[b - 1] = mul(add(b % mod, mod), add(a % mod, mod));
            }

            ll sum = 0;
            for (const auto [b, a] : Gs) { sum = add(sum, mul(a, pow(pow, n, b))); }
            if (sum != 0) { return false; }
        }
        return true;
    };
    for (const ll n : ns) {
        if (check(n)) {
            std::cout << "Yes " << n << std::endl;
            return 0;
        }
    }
    std::cout << "No" << std::endl;
    return 0;
}
accuracy: 1
time_ms: 2890
memory_kb: 3556
final_rank: 5

code_snippet: #include <bits/stdc++.h>
int main()
{
    using ll = long long;
    int N;
    std::cin >> N;
    std::map<ll, ll> Fs;
    for (int i = 0; i < N; i++) {
        ll o, p;
        std::cin >> o >> p;
        Fs[o] += p;
        if (Fs[o] == 0) { Fs.erase(o); }
    }
    auto sqrt = [&](const ll n) {
        const ll x = (ll)std::sqrt(n) - 100;
        const ll y = (ll)std::sqrt(n) * 2 + 100;
        for (ll i = std::max(0LL, x); i <= y; i++) {
            if (i * i == n) { return i; }
        }
        return -1LL;
    };
    if (Fs.empty()) {
        std::cout << "Yes " << 1 << std::endl;
        return 0;
    }
    const auto A = std::abs(Fs.begin()->second);
    std::set<ll> ns;
    for (ll i = 1; i <= 1000000; i++) {
        if (A % (i * i) == 0) {
            ns.insert(i);
            const ll B = A / i;
            const ll b = sqrt(B);
            if (b != -1) { ns.insert(b); }
        }
    }
    ns.erase(0);

    constexpr int MN      = 3;
    constexpr ll mods[MN] = {1000000007, 1000000009, 998244353};
    auto check            = [&](const ll n) {
        for (int i = 0; i < MN; i++) {
            const ll mod = mods[i];
            auto add     = [&](const ll i, const ll j) { return (i + j) % mod; };
            auto mul     = [&](const ll i, const ll j) { return (i * j) % mod; };
            auto pow     = [&](auto self, const ll i, const ll n) -> ll { return n == 0 ? 1 : n % 2 == 0 ? self(self, mul(i, i), n / 2) : mul(self(self, i, n - 1), i); };
            std::map<ll, ll> Gs;
            for (const auto [b, a] : Fs) { Gs[b] = add(a % mod, mod); }

            ll sum = 0;
            for (const auto [b, a] : Gs) { sum = add(sum, mul(a, pow(pow, n, b))); }
            if (sum != 0) { return false; }
        }
        for (int i = 0; i < MN; i++) {
            const ll mod = mods[i];
            auto add     = [&](const ll i, const ll j) { return (i + j) % mod; };
            auto mul     = [&](const ll i, const ll j) { return (i * j) % mod; };
            auto pow     = [&](auto self, const ll i, const ll n) -> ll { return n == 0 ? 1 : n % 2 == 0 ? self(self, mul(i, i), n / 2) : mul(self(self, i, n - 1), i); };
            std::map<ll, ll> Gs;
            for (const auto [b, a] : Fs) {
                if (b == 0) { continue; }
                Gs[b - 1] = mul(add(b % mod, mod), add(a % mod, mod));
            }

            ll sum = 0;
            for (const auto [b, a] : Gs) { sum = add(sum, mul(a, pow(pow, n, b))); }
            if (sum != 0) { return false; }
        }
        return true;
    };
    for (const ll n : ns) {
        if (check(n)) {
            std::cout << "Yes " << n << std::endl;
            return 0;
        }
    }
    std::cout << "No" << std::endl;
    return 0;
}
accuracy: 0.19298245614035087
time_ms: 1060
memory_kb: 3496
final_rank: 9

code_snippet: #include <bits/stdc++.h>
int main()
{
    using ll = long long;
    int N;
    std::cin >> N;
    std::map<ll, ll> Fs;
    for (int i = 0; i < N; i++) {
        ll o, p;
        std::cin >> o >> p;
        Fs[o] += p;
    }
    auto sqrt = [&](const ll n) {
        const ll x = (ll)std::sqrt(n) - 100;
        const ll y = (ll)std::sqrt(n) * 2 + 100;
        for (ll i = std::max(0LL, x); i <= y; i++) {
            if (i * i == n) { return i; }
        }
        return -1LL;
    };
    const auto A = std::abs(Fs.begin()->second);
    std::set<ll> ns;
    for (ll i = 1; i <= 1000000; i++) {
        if (A % (i * i) == 0) {
            ns.insert(i);
            const ll B = A / i;
            const ll b = sqrt(B);
            if (b != -1) { ns.insert(b); }
        }
    }

    constexpr int MN      = 3;
    constexpr ll mods[MN] = {1000000007, 1000000009, 998244353};
    auto check            = [&](const ll n) {
        for (int i = 0; i < MN; i++) {
            const ll mod = mods[i];
            auto add     = [&](const ll i, const ll j) { return (i + j) % mod; };
            auto mul     = [&](const ll i, const ll j) { return (i * j) % mod; };
            auto pow     = [&](auto self, const ll i, const ll n) -> ll { return n == 0 ? 1 : n % 2 == 0 ? self(self, mul(i, i), n / 2) : mul(self(self, i, n - 1), i); };
            std::map<ll, ll> Gs;
            for (const auto [b, a] : Fs) { Gs[b] = add(a % mod, mod); }

            ll sum = 0;
            for (const auto [b, a] : Gs) { sum = add(sum, mul(a, pow(pow, n, b))); }
            if (sum != 0) { return false; }
        }
        for (int i = 0; i < MN; i++) {
            const ll mod = mods[i];
            auto add     = [&](const ll i, const ll j) { return (i + j) % mod; };
            auto mul     = [&](const ll i, const ll j) { return (i * j) % mod; };
            auto pow     = [&](auto self, const ll i, const ll n) -> ll { return n == 0 ? 1 : n % 2 == 0 ? self(self, mul(i, i), n / 2) : mul(self(self, i, n - 1), i); };
            std::map<ll, ll> Gs;
            for (const auto [b, a] : Fs) {
                if (b == 0) { continue; }
                Gs[b - 1] = mul(add(b % mod, mod), add(a % mod, mod));
            }

            ll sum = 0;
            for (const auto [b, a] : Gs) { sum = add(sum, mul(a, pow(pow, n, b))); }
            if (sum != 0) { return false; }
        }
        return true;
    };
    for (const ll n : ns) {
        if (check(n)) {
            std::cout << "Yes " << n << std::endl;
            return 0;
        }
    }
    std::cout << "No" << std::endl;
    return 0;
}
accuracy: 0.19298245614035087
time_ms: 450
memory_kb: 3572
final_rank: 8

code_snippet: #include <bits/stdc++.h>
int main()
{
    using ll = long long;
    int N;
    std::cin >> N;
    std::map<ll, ll> Fs;
    for (int i = 0; i < N; i++) {
        ll o, p;
        std::cin >> o >> p;
        Fs[o] += p;
    }
    auto sqrt = [&](const ll n) {
        const ll x = (ll)std::sqrt(n);
        const ll y = (ll)std::sqrt(n) * 2;
        for (ll i = x; i <= y; i++) {
            if (i * i == n) { return i; }
        }
        return -1LL;
    };
    const auto A = std::abs(Fs.begin()->second);
    std::set<ll> ns;
    for (ll i = 1; i <= 1000000; i++) {
        if (A % (i * i) == 0) {
            ns.insert(i);
            const ll B = A / i;
            const ll b = sqrt(B);
            if (b != -1) { ns.insert(b); }
        }
    }
    // std::cerr << "ns = [";
    // for (const ll n : ns) { std::cerr << n << ","; }
    // std::cerr << "]" << std::endl;

    constexpr int MN      = 2;
    constexpr ll mods[MN] = {1000000007, 1000000009};
    auto check            = [&](const ll n) {
        for (int i = 0; i < MN; i++) {
            const ll mod = mods[i];
            auto add     = [&](const ll i, const ll j) { return (i + j) % mod; };
            auto mul     = [&](const ll i, const ll j) { return (i * j) % mod; };
            auto pow     = [&](auto self, const ll i, const ll n) -> ll { return n == 0 ? 1 : n % 2 == 0 ? self(self, mul(i, i), n / 2) : mul(self(self, i, n - 1), i); };
            auto Gs      = Fs;
            for (auto& [b, a] : Gs) { a %= mod, (a += mod) %= mod; }
            ll sum = 0;
            for (const auto [b, a] : Gs) { sum = add(sum, mul(a, pow(pow, n, b))); }
            if (sum != 0) { return false; }
        }
        for (int i = 0; i < MN; i++) {
            const ll mod = mods[i];
            auto add     = [&](const ll i, const ll j) { return (i + j) % mod; };
            auto mul     = [&](const ll i, const ll j) { return (i * j) % mod; };
            auto pow     = [&](auto self, const ll i, const ll n) -> ll { return n == 0 ? 1 : n % 2 == 0 ? self(self, mul(i, i), n / 2) : mul(self(self, i, n - 1), i); };
            std::map<ll, ll> Gs;
            for (const auto [b, a] : Fs) {
                if (b == 0) { continue; }
                Gs[b - 1] = mul(add(b % mod, mod), add(a % mod, mod));
            }
            ll sum = 0;
            for (const auto [b, a] : Gs) { sum = add(sum, mul(a, pow(pow, n, b))); }
            if (sum != 0) { return false; }
        }
        return true;
    };
    for (const ll n : ns) {
        if (check(n)) {
            std::cout << "Yes " << n << std::endl;
            return 0;
        }
    }
    std::cout << "No" << std::endl;
    return 0;
}
accuracy: 0.19298245614035087
time_ms: 450
memory_kb: 3500
final_rank: 7

code_snippet: #include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << x << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
int N;
typedef long long ll;
map<ll,ll> f,f_;
const int T=1;
ll mod=1145141919;
ll ex(ll x,ll p){
	ll a=1;
	if(p<0) return 0;
	while(p){
		if(p%2) a=a*x%mod;
		x=x*x%mod;
		p/=2;
	}
	return a;
}
void add(ll &x,ll y){
	x+=y;
	x%=mod;
}

const ll ccc=1000000;
bool prime[ccc+1];
vector<ll> pr;
void makeprime(){
	ll i,j;
	for(i=2;i<=ccc;i++) prime[i]=true;
	for(i=2;i*i<=ccc;i++) if(prime[i]) for(j=2;j*i<=ccc;j++) prime[j*i]=false;
	for(i=2;i<=ccc;i++) if(prime[i]) pr.push_back(i);
}

map<ll,int> fac;
vector<ll> ds;
void dfs(map<ll,int>::iterator it,ll d){
	if(it==fac.end()){
		ds.pb(d);
		return;
	}
	ll p=it->fs,q=it->sc,t=1;
	auto it2=it;
	it2++;
	rep(i,q/2+1){
		dfs(it2,d*t);
		t*=p;
	}
}
int main(){
	makeprime();
	cin>>N;
	rep(i,N){
		ll a,b;
		cin>>a>>b;
		f_[a]+=b;
	}
	for(auto p:f_) if(p.sc!=0) f[p.fs]=p.sc;
	if(f.empty()){
		puts("Yes 1");
		return 0;
	}
	ll c=abs(f.begin()->sc);
//	show(c);
	ll tmp=c;
	for(ll p:pr){
		while(tmp%p==0) tmp/=p,fac[p]++;
	}
	if(tmp>1){
		ll a=round(sqrt(tmp));
		if(a*a==tmp) fac[a]=2;
	}
	dfs(fac.begin(),1);
	sort(all(ds));
	for(ll a:ds){
		bool ok=1;
		ll x=0;
		for(auto p:f) add(x,p.sc%mod*ex(a,p.fs));
		if(x!=0) ok=0;
		x=0;
		for(auto p:f) add(x,-p.sc%mod*p.fs%mod*ex(a,p.fs-1));
		if(x!=0) ok=0;
		if(ok){
			cout<<"Yes "<<a<<endl;
			return 0;
		}
	}
	puts("No");
}
accuracy: 1
time_ms: 30
memory_kb: 2968
final_rank: 3

code_snippet: #include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << x << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
int N;
typedef long long ll;
map<ll,ll> f,f_;
const int T=1;
ll ms[1]={1145141919},mod;
ll ex(ll x,ll p){
	ll a=1;
	if(p<0) return 0;
	while(p){
		if(p%2) a=a*x%mod;
		x=x*x%mod;
		p/=2;
	}
	return a;
}
void add(ll &x,ll y){
	x+=y;
	x%=mod;
}
int main(){
//	srand((unsigned)time(NULL));
//	rep(i,T) ms[i]=rand()%1000000000+2;
	cin>>N;
	rep(i,N){
		ll a,b;
		cin>>a>>b;
		f_[a]+=b;
	}
	for(auto p:f_) if(p.sc!=0) f[p.fs]=p.sc;
	if(f.empty()){
		puts("Yes 1");
		return 0;
	}
	ll c=abs(f.begin()->sc);
	vector<ll> ds;
//	show(c);
	ll tmp=c;
	for(ll i=1;i<=1e6;i++){
		if(c%i==0) ds.pb(i);
		if(i>1){
			while(tmp%i==0) tmp/=i;
		}
	}
	if(tmp>1){
		ll a=round(sqrt(tmp));
		if(a*a==tmp){
			int K=ds.size();
			rep(i,K) ds.pb(ds[i]*a);
		}
	}
	sort(all(ds));
//	show(ds.size());
	for(ll a:ds){
		if(a>1e9) break;
		if(c%(a*a)) continue;
		bool ok=1;
		rep(i,T){
			mod=ms[i];
			ll x=0;
			for(auto p:f) add(x,p.sc%mod*ex(a,p.fs));
			if(x!=0) ok=0;
			x=0;
			for(auto p:f) add(x,-p.sc%mod*p.fs%mod*ex(a,p.fs-1));
			if(x!=0) ok=0;
		}
		if(ok){
			cout<<"Yes "<<a<<endl;
			return 0;
		}
	}
	puts("No");
}
accuracy: 0.19298245614035087
time_ms: 30
memory_kb: 1312
final_rank: 6

code_snippet: #include<stdio.h>
#include<queue>
#include<algorithm>
#include<math.h>
using namespace std;
long long mod=1000000033;
int p[1100];
long long q[1100];
long long hb[114514];
int sz=0;
int n;
long long pow(long long a,long long b){
	long long ret=1;
	while(b){
		if(b%2)ret=ret*a%mod;
		b/=2;
		a=a*a%mod;
	}
	return ret;
}
long long calc(long long x){
	long long now=0;
	for(int i=0;i<n;i++){
		now=(now+pow(x,p[i])*((mod+q[i])%mod))%mod;
	}
	return now;
}
long long ABS(long long a){return max(a,-a);}
long long np[1100];
long long nq[1100];
int v[1100];
int ns;
int main(){
	int a;scanf("%d",&a);
	n=a;
	for(int i=0;i<a;i++){
		scanf("%d%lld",p+i,q+i);
	}
	for(int i=0;i<a;i++){
		if(v[i])continue;
		long long tmp=0;
		for(int j=0;j<a;j++){
			if(p[i]==p[j]){
				tmp+=q[j];
				v[j]=1;
			}
		}
		if(tmp){
			np[ns]=p[i];
			nq[ns]=tmp;
			ns++;
		}
	}
	for(int i=0;i<ns;i++){
		p[i]=np[i];
		q[i]=nq[i];
	}
	a=ns;
	n=ns;
	long long deg=0;
	for(int i=0;i<a;i++)deg=max(deg,(long long)p[i]);
	long long dm=999999999999LL;
	for(int i=0;i<a;i++)dm=min(dm,(long long)p[i]);
	if(deg<=1){
		long long A=0;
		long long B=0;
		for(int i=0;i<a;i++){
			if(p[i]==1)A+=q[i];
			else B+=q[i];
		}
		if(A<0){
			A=-A;B=-B;
		}
		if(A==0){
			if(B==0)printf("Yes 1\n");
			else printf("No\n");
		}else{
			printf("No\n");
		}
		return 0;
	}
	long long t=0;
	for(int i=0;i<a;i++)if(p[i]==dm)t+=q[i];
	long long m=t;
	t=ABS(t);
	long long ret=99999999999999999LL;
	for(int i=1;(long long)i*i*i<=t;i++){
		if(t%i==0){
			if((t/i)%i==0){
				hb[sz++]=i;
			}
			long long s=t/i;
			long long u=(long long)(sqrt(s)+0.00001);
			if(u*u==s)hb[sz++]=u;
		}
	}
	std::sort(hb,hb+sz);
	for(int i=0;i<sz;i++){
	//	printf("%lld\n",hb[i]);
		if(calc(hb[i])==0LL){
			printf("Yes %lld\n",hb[i]);return 0;
		}
	}
	printf("No\n");
}
accuracy: 1
time_ms: 10
memory_kb: 1080
final_rank: 1

code_snippet: #include<map>
#include<cmath>
#include<cstdio>
#include<vector>
#include<algorithm>

#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

typedef long long ll;

ll gcd(ll a,ll b){ return b?gcd(b,a%b):a; }

ll fast_modmul(ll a,ll b,ll m){
	return (((a*(b>>20)%m)<<20)+a*(b&((1<<20)-1)))%m;
}

ll fast_modpow(ll a,ll n,ll m){
	ll r=1;
	for(ll x=a%m;n;n>>=1,x=(x*x)%m) if(n&1) r=(r*x)%m;
	return r;
}

ll modmul(ll a,ll b,ll m){
	ll r=0;
	for(;b;b>>=1,a=(a<<1)%m) if(b&1) r=(r+a)%m;
	return r;
}

ll modpow(ll a,ll n,ll m){
	ll r=1;
	for(ll x=a%m;n;n>>=1,x=modmul(x,x,m)) if(n&1) r=modmul(r,x,m);
	return r;
}

bool Miller_Rabin(ll n){
	if(n<=1)   return false;
	if(!(n&1)) return n==2;
	if(n%3==0) return n==3;

	int s=0; // n-1 = 2^s * d (d: odd)
	ll d=n-1;
	while(!(d&1)) s++, d>>=1;

	const static ll a[]={2,3,5,7,11,13,17,19,23};
	rep(i,sizeof a/sizeof(ll)){
		if(a[i]>=n) break;

		ll x=modpow(a[i],d,n);
		if(x==1 || x==n-1) continue;
		bool b=false;
		for(int r=1;r<s;r++){
			x=modmul(x,x,n);
			if(x== 1 ) return false;
			if(x==n-1){ b=true; break; }
		}
		if(!b) return false;
	}

	return true;
}

ll Pollard_rho(ll n,int c){
	if((n&1)==0) return 2;

	ll x=2,y=2,d=1;
	while(d==1){
		x=modmul(x,x,n)+c; if(x<0) x+=n;
		y=modmul(y,y,n)+c; if(y<0) y+=n;
		y=modmul(y,y,n)+c; if(y<0) y+=n;
		d=gcd(llabs(x-y),n);
	}
	return d<n?d:-1;
}

void prime_factorize(ll n,map<ll,int> &pf){
	if(n<=1) return;
	if(Miller_Rabin(n)){ ++pf[n]; return; }

	ll d;
	for(int c=1;;c++){
		d=Pollard_rho(n,c);
		if(d!=-1) break;
	}

	prime_factorize( d ,pf);
	prime_factorize(n/d,pf);
}

void dfs(int i,ll a,const vector< pair<ll,int> > &pf,vector<ll> &res){
	if(i==pf.size()){
		res.push_back(a);
		return;
	}

	dfs(i+1,a,pf,res);
	rep(j,pf[i].second){
		a*=pf[i].first;
		dfs(i+1,a,pf,res);
	}
}

const ll M=1000000007;

int main(){
	int n; scanf("%d",&n);
	ll o[1000],p[1000];
	rep(i,n) scanf("%lld%lld",o+i,p+i);

	rep(i,n){
		rep(j,i) if(o[i]==o[j]) {
			p[j]+=p[i];
			swap(o[i],o[n-1]);
			swap(p[i],p[n-1]);
			i--;
			n--;
			break;
		}
	}

	// 多項式 Σ p[i] * x^o[i] の正の重根を求めればよい

	// 0 は答えじゃないので x^hoge で割って定数項が見えるようにする
	ll o_min=*min_element(o,o+n);
	rep(i,n) o[i]-=o_min;

	ll c; // 定数項
	rep(i,n) if(o[i]==0) c=p[i];

	map<ll,int> pf;
	prime_factorize(llabs(c),pf);

	vector<ll> d; // c の約数全体
	vector< pair<ll,int> > pf2(pf.begin(),pf.end());
	dfs(0,1,pf2,d);

	sort(d.begin(),d.end());

	rep(i,d.size()){
		ll x=d[i];

		if(x>M) break; // 大きい約数はどうせ答えじゃないので見ない ( TLE がきつい!! )

		ll val1=0,val2=0;
		rep(i,n){
			ll q=llabs(p[i])%M;
			int sgn=(p[i]>0?1:-1);
			val1=(val1+sgn*fast_modmul(q,fast_modpow(x%M,o[i],M),M)+M)%M;
			if(o[i]>0){
				val2=(val2+sgn*fast_modmul(fast_modmul(o[i],q,M),fast_modpow(x%M,o[i]-1,M),M)+M)%M;
			}
		}

		if(val1==0 && val2==0){ printf("Yes %lld\n",x); return 0; }
	}

	puts("No");

	return 0;
}
accuracy: 1
time_ms: 50
memory_kb: 1100
final_rank: 2