Problem:
Score : 1100 points

Problem Statement

We have N balance beams numbered 1 to N.
The length of each beam is 1 meters.
Snuke walks on Beam i at a speed of 1/A_i meters per second, and Ringo walks on Beam i at a speed of 1/B_i meters per second.

Snuke and Ringo will play the following game:

First, Snuke connects the N beams in any order of his choice and makes a long beam of length N meters.

Then, Snuke starts at the left end of the long beam. At the same time, Ringo starts at a point chosen uniformly at random on the long beam. Both of them walk to the right end of the long beam.

Snuke wins if and only if he catches up to Ringo before Ringo reaches the right end of the long beam. That is, Snuke wins if there is a moment when Snuke and Ringo stand at the same position, and Ringo wins otherwise.

Find the probability that Snuke wins when Snuke arranges the N beams so that the probability of his winning is maximized.

This probability is a rational number, so we ask you to represent it as an irreducible fraction P/Q (to represent 0, use P=0, Q=1).

Constraints

1 \leq N \leq 10^5

1 \leq A_i,B_i \leq 10^9

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
A_1 B_1
A_2 B_2
\vdots
A_N B_N

Output

Print the numerator and denominator of the irreducible fraction that represents the maximum probability of Snuke's winning.

Sample Input 1

2
3 2
1 2

Sample Output 1

1 4

When the beams are connected in the order 2,1 from left to right, the probability of Snuke's winning is 1/4, which is the maximum possible value.

Sample Input 2

4
1 5
4 7
2 1
8 4

Sample Output 2

1 2

Sample Input 3

3
4 1
5 2
6 3

Sample Output 3

0 1

Sample Input 4

10
866111664 178537096
705445072 318106937
472381277 579910117
353498483 865935868
383133839 231371336
378371075 681212831
304570952 16537461
955719384 267238505
844917655 218662351
550309930 62731178

Sample Output 4

697461712 2899550585

Solution in C++14 (GCC 5.4.1) (judge verdict: Wrong Answer)

#include <bits/stdc++.h>

using namespace std;

#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define REV(i,n) for(ll (i) = (n) - 1;(i) >= 0;--i)
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {REP(WW,n)cerr << v[WW] << ' ';cerr << endl << endl;}
#define SHOW2d(v,WW,HH) {REP(W_,WW){REP(H_,HH)cerr << v[W_][H_] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 998244353

typedef long long ll;
typedef pair<ll,ll> P;

ll pla;
ll amari;
ll cou;
vector<P> small;
vector<pair<ll, P>> large;

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

bool seica(ll now, bool flag){
	ll tmp_amari = amari;
	ll tmp_cou = cou;
	while(tmp_cou < small.size() && now > 0){
		ll tmp = min(now, small[tmp_cou].FI - tmp_amari);
		now -= tmp;
		tmp_amari += tmp;
		if(tmp_amari == small[tmp_cou].FI){
			tmp_cou++;
			tmp_amari = 0;
		}
	}

	if(tmp_cou == small.size() && now > 0){
		return false;
	}

	if(flag || cou == tmp_cou || (tmp_cou == small.size() && cou == small.size() - 1) || (tmp_amari * small[cou].FI < amari * small[tmp_cou].FI && tmp_cou == cou + 1)){
		cou = tmp_cou;
		amari = tmp_amari;
		return true;
	}
	return false;
}

int main(){
	cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);

	ll n;cin >> n;
	ll sum_a = 0;

	REP(i, n){
		ll a, b;cin >> a >> b;
		if(a <= b){
			small.EB(b, a);
			sum_a += a;
		}
		else large.EB(a, MP(a, b));
	}

	sort(ALL(small), greater<P>());
	sort(ALL(large));

	seica(sum_a, true);
	REP(i, large.size()){
		if(seica(large[i].SE.FI, false) == false)pla++;
		else small.EB(large[i].SE.SE, large[i].SE.FI);
	}

	ll p, q;
	if(amari){
		p = n * small[cou].FI - small[cou].FI * (pla + cou) - amari;
		q = n * small[cou].FI;
		ll gcd_num = gcd(p, q);
		p /= gcd_num;
		q /= gcd_num;
	}
	else {
		p = n - (pla + cou);
		q = n;
		ll gcd_num = gcd(p, q);
		p /= gcd_num;
		q /= gcd_num;
	}
	cout << p << " " << q << endl;

	return 0;
}