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)

#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
void *wmem;
char memarr[96000000];
template<class S, class T> inline S max_L(S a,T b){
  return a>=b?a:b;
}
template<class T> inline void walloc1d(T **arr, int x, void **mem = &wmem){
  static int skip[16] = {0, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1};
  (*mem) = (void*)( ((char*)(*mem)) + skip[((unsigned long long)(*mem)) & 15] );
  (*arr)=(T*)(*mem);
  (*mem)=((*arr)+x);
}
template<class T1, class T2> void sortA_L(int N, T1 a[], T2 b[], void *mem = wmem){
  int i;
  pair<T1, T2> *arr;
  walloc1d(&arr, N, &mem);
  for(i=(0);i<(N);i++){
    arr[i].first = a[i];
    arr[i].second = b[i];
  }
  sort(arr, arr+N);
  for(i=(0);i<(N);i++){
    a[i] = arr[i].first;
    b[i] = arr[i].second;
  }
}
template<class T1, class T2, class T3> void sortA_L(int N, T1 a[], T2 b[], T3 c[], void *mem = wmem){
  int i;
  pair<T1, pair<T2, T3> > *arr;
  walloc1d(&arr, N, &mem);
  for(i=(0);i<(N);i++){
    arr[i].first = a[i];
    arr[i].second.first = b[i];
    arr[i].second.second = c[i];
  }
  sort(arr, arr+N);
  for(i=(0);i<(N);i++){
    a[i] = arr[i].first;
    b[i] = arr[i].second.first;
    c[i] = arr[i].second.second;
  }
}
inline void rd(int &x){
  int k;
  int m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline void rd(long long &x){
  int k;
  int m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline void wt_L(char a){
  putchar_unlocked(a);
}
inline void wt_L(long long x){
  int s=0;
  int m=0;
  char f[20];
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    putchar_unlocked('-');
  }
  while(s--){
    putchar_unlocked(f[s]+'0');
  }
}
template<class T> inline T GCD_L(T a,T b){
  T r;
  while(a){
    r=b;
    b=a;
    a=r%a;
  }
  return b;
}
template<class T> struct Heap{
  int size;
  T *val;
  void malloc(const int N){
    val = (T*) std::malloc(N*sizeof(T));
    size = 0;
  }
  void walloc(const int N, void **mem = &wmem){
    walloc1d(&val, N, mem);
    size = 0;
  }
  void free(){
    std::free(val);
  }
  void init(){
    size = 0;
  }
  void up(){
    int n = size - 1;
    int m;
    while(n){
      m = (n-1) / 2;
      if(val[m] <= val[n]){
        break;
      }
      swap(val[m], val[n]);
      n = m;
    }
  }
  void down(){
    int n = 0;
    int m;
    for(;;){
      m=2*n+1;
      if(m>=size){
        break;
      }
      if(m+1<size && val[m] > val[m+1]){
        m++;
      }
      if(val[m] >= val[n]){
        break;
      }
      swap(val[m], val[n]);
      n = m;
    }
  }
  T top(){
    return val[0];
  }
  T pop(){
    T res = val[0];
    size--;
    if(size > 0){
      val[0] = val[size];
      down();
    }
    return res;
  }
  T push(const T x){
    val[size++] = x;
    up();
    return x;
  }
}
;
template<class T> struct Heap_max{
  int size;
  T *val;
  void malloc(const int N){
    val = (T*) std::malloc(N*sizeof(T));
    size = 0;
  }
  void walloc(const int N, void **mem = &wmem){
    walloc1d(&val, N, mem);
    size = 0;
  }
  void free(){
    std::free(val);
  }
  void init(){
    size = 0;
  }
  void up(){
    int n = size - 1;
    int m;
    while(n){
      m = (n-1) / 2;
      if(val[m] >= val[n]){
        break;
      }
      swap(val[m], val[n]);
      n = m;
    }
  }
  void down(){
    int n = 0;
    int m;
    for(;;){
      m=2*n+1;
      if(m>=size){
        break;
      }
      if(m+1<size && val[m] < val[m+1]){
        m++;
      }
      if(val[m] <= val[n]){
        break;
      }
      swap(val[m], val[n]);
      n=m;
    }
  }
  T top(){
    return val[0];
  }
  T pop(){
    T res = val[0];
    size--;
    if(size > 0){
      val[0] = val[size];
      down();
    }
    return res;
  }
  T push(const T x){
    val[size++] = x;
    up();
    return x;
  }
}
;
int N;
long long A[100000];
long long B[100000];
long long val[100000];
long long arr[100000];
double vald[100000];
long long res1;
long long res2;
void update(long long a, long long b){
  double d1;
  double d2;
  long long g;
  g =GCD_L(a, b);
  a /= g;
  b /= g;
  d1 = (double) a / b;
  d2 = (double) res1 / res2;
  if(d1 > d2){
    res1 = a;
    res2 = b;
  }
}
int main(){
  int loop;
  wmem = memarr;
  long long up;
  long long dw;
  long long tm;
  Heap<long long> done;
  Heap_max<long long> yet;
  rd(N);
  {
    int KL2GvlyY;
    for(KL2GvlyY=(0);KL2GvlyY<(N);KL2GvlyY++){
      rd(A[KL2GvlyY]);
      rd(B[KL2GvlyY]);
    }
  }
  res1 = 0;
  res2 = 1;
  done.malloc(N);
  yet.malloc(N);
  for(loop=(0);loop<(13);loop++){
    int x;
    done.init();
    yet.init();
    if(loop==0){
      int i;
      for(i=(0);i<(N);i++){
        vald[i] = A[i] - B[i];
      }
    }
    if(loop==1){
      int i;
      for(i=(0);i<(N);i++){
        vald[i] = B[i] - A[i];
      }
    }
    if(loop==2){
      int i;
      for(i=(0);i<(N);i++){
        vald[i] = A[i] + B[i];
      }
    }
    if(loop==3){
      int i;
      for(i=(0);i<(N);i++){
        vald[i] = 1.0 / A[i] - 1.0 / B[i];
      }
    }
    if(loop==4){
      int i;
      for(i=(0);i<(N);i++){
        vald[i] = 1.0 / B[i] - 1.0 / A[i];
      }
    }
    if(loop==5){
      int i;
      for(i=(0);i<(N);i++){
        vald[i] = (double) A[i] / B[i];
      }
    }
    if(loop==6){
      int i;
      for(i=(0);i<(N);i++){
        vald[i] = (double) B[i] / A[i];
      }
    }
    if(loop==7){
      int i;
      for(i=(0);i<(N);i++){
        vald[i] = A[i];
      }
    }
    if(loop==8){
      int i;
      for(i=(0);i<(N);i++){
        vald[i] = -A[i];
      }
    }
    if(loop==9){
      int i;
      for(i=(0);i<(N);i++){
        vald[i] = B[i];
      }
    }
    if(loop==10){
      int i;
      for(i=(0);i<(N);i++){
        vald[i] = -B[i];
      }
    }
    if(loop==11){
      int i;
      for(i=(0);i<(N);i++){
        vald[i] =max_L(A[i], B[i]);
      }
    }
    if(loop==12){
      int i;
      for(i=(0);i<(N);i++){
        vald[i] = -max_L(A[i], B[i]);
      }
    }
    sortA_L(N, vald, A, B);
    tm = 0;
    for(x=(0);x<(N);x++){
      tm += A[x];
      yet.push(B[x]);
      while(yet.size && done.size && done.top() < yet.top()){
        up = done.pop();
        dw = yet.pop();
        tm += up - dw;
        done.push(dw);
        yet.push(up);
      }
      while(done.size && tm <= 0){
        tm += yet.push(done.pop());
      }
      while(yet.size && tm > yet.top()){
        tm -= done.push(yet.pop());
      }
      if(yet.size==0){
        continue;
      }
      up = yet.size * yet.top() - tm;
      dw = N * yet.top();
      update(up,dw);
    }
  }
  wt_L(res1);
  wt_L(' ');
  wt_L(res2);
  wt_L('\n');
  return 0;
}
// cLay varsion 20191102-1

// --- original code ---
// int N;
// ll A[1d5], B[1d5], val[1d5], arr[1d5];
// double vald[1d5];
// 
// ll res1, res2;
// 
// void update(ll a, ll b){
//   double d1, d2;
//   ll g;
//   g = gcd(a,b);
//   a /= g;
//   b /= g;
//   d1 = (double) a / b;
//   d2 = (double) res1 / res2;
// //  wt(d1,d2,":",a,b,res1,res2);
// //  if((__int128_t) a*res2 > (__int128_t)res1*b){
//   if(d1 > d2){
//     res1 = a;
//     res2 = b;
//   }
// }
// 
// {
//   ll up, dw, tm;
//   Heap<ll> done;
//   Heap_max<ll> yet;
// 
//   rd(N,(A,B)(N));
// 
//   res1 = 0; res2 = 1;
//   done.malloc(N);
//   yet.malloc(N);
// 
// 
//   rep(loop,13){
//     done.init();
//     yet.init();
// 
//     if(loop==0) rep(i,N) vald[i] = A[i] - B[i];
//     if(loop==1) rep(i,N) vald[i] = B[i] - A[i];
//     if(loop==2) rep(i,N) vald[i] = A[i] + B[i];
//     if(loop==3) rep(i,N) vald[i] = 1.0 / A[i] - 1.0 / B[i];
//     if(loop==4) rep(i,N) vald[i] = 1.0 / B[i] - 1.0 / A[i];
//     if(loop==5) rep(i,N) vald[i] = (double) A[i] / B[i];
//     if(loop==6) rep(i,N) vald[i] = (double) B[i] / A[i];
//     if(loop==7) rep(i,N) vald[i] = A[i];
//     if(loop==8) rep(i,N) vald[i] = -A[i];
//     if(loop==9) rep(i,N) vald[i] = B[i];
//     if(loop==10) rep(i,N) vald[i] = -B[i];
//     if(loop==11) rep(i,N) vald[i] = max(A[i],B[i]);
//     if(loop==12) rep(i,N) vald[i] = -max(A[i],B[i]);
//     sortA(N, vald, A, B);
// 
//     tm = 0;
//     rep(x,N){
//       tm += A[x];
//       yet.push(B[x]);
// 
//       while(yet.size && done.size && done.top() < yet.top()){
//         up = done.pop();
//         dw = yet.pop();
//         tm += up - dw;
//         done.push(dw);
//         yet.push(up);
//       }
//       while(done.size && tm <= 0) tm += yet.push(done.pop());
//       while(yet.size && tm > yet.top()) tm -= done.push(yet.pop());
//       if(yet.size==0) continue;
// 
//       up = yet.size * yet.top() - tm;
//       dw = N * yet.top();
//       update(up,dw);
//     }
//   }
// 
//   wt(res1, res2);
// //  double res;
// //  res = (double)res1 / res2;
// //  wt(res);
// }