#include <bits/stdc++.h>
using namespace std;
const int N = 200010;
int t;
long long e[N], s[N];
bool can[N][4];
bool get(long long e, long long s, bool S) {
  bool a[2] = {S, S}, tmp[2];
  if (s > e) return S;
  while (true) {
    if (a[0] == false) {
      tmp[0] = tmp[1] = true;
    } else {
      bool A = (e & 1);
      if (a[A ^ 1] == false)
        tmp[A] = true, tmp[A ^ 1] = false;
      else
        tmp[A] = false, tmp[A ^ 1] = true;
    }
    a[0] = tmp[0], a[1] = tmp[1];
    if (s > e / 2 && s <= e) return a[(s & 1)];
    e /= 2;
  }
  assert(false);
  return false;
}
bool start[2], tmpstart[2];
int main() {
  scanf("%d", &t);
  start[0] = true;
  for (int i = 0; i < t; i++) {
    scanf("%lld%lld", &s[i], &e[i]);
    can[i][0] = get(e[i], s[i], false);
    can[i][1] = get(e[i], s[i], true);
    can[i][2] = (get(e[i], s[i] + 1, false) && get(e[i], s[i] * 2, false));
    can[i][3] = (get(e[i], s[i] + 1, true) && get(e[i], s[i] * 2, true));
    tmpstart[0] = tmpstart[1] = false;
    if (start[0]) {
      if (can[i][0]) tmpstart[0] = true;
      if (can[i][1]) tmpstart[1] = true;
    }
    if (start[1]) {
      if (can[i][2]) tmpstart[0] = true;
      if (can[i][3]) tmpstart[1] = true;
    }
    start[0] = tmpstart[0], start[1] = tmpstart[1];
  }
  cout << start[1] << " " << start[0] << endl;
  return 0;
}
