#include <bits/stdc++.h>
using ll = long long;
const int MT = 1e5 + 10;
int T, v[10];
ll s[MT], e[MT];
int get(int a, int b) {
  int f = 0;
  f |= (a >> 2 & 1 | b >> 2 & 1) << 0;
  f |= (a >> 3 & 1 | b >> 3 & 1) << 1;
  f |= (a >> 0 & b >> 0 & 1) << 2;
  f |= (a >> 1 & b >> 1 & 1) << 3;
  return f;
}
int flip(int a) { return a >> 2 | (a & 3) << 2; }
int main() {
  scanf("%d", &T);
  for (int i = 0; i < T; ++i) scanf("%lld%lld", s + i, e + i);
  int p = 0b0110;
  for (int i = T - 1; i >= 0; --i) {
    p = flip(p);
    int n = p, j = p;
    for (ll x = e[i], nx;; x = nx) {
      nx = x / 2;
      v[0] = get(j, n);
      v[1] = get(j, v[0]);
      assert(v[0] == get(j, v[1]));
      if (s[i] > nx) {
        p = v[(s[i] ^ x) & 1];
        break;
      } else {
        n = v[(nx + 1 ^ x) & 1];
        j = v[x & 1];
      }
    }
  }
  printf("%d %d\n", p & 1, p >> 1 & 1);
  return 0;
}
