#include <iostream>
#include <cstdio>
#include <cstring>
#include <ctype.h>
#include <algorithm>
#include <fstream>
#include <climits>
#define mp make_pair
#define x first
#define y second

using namespace std;

typedef long long LL;
typedef pair<int, int> pii;
typedef pair<LL, LL> pll;
typedef pair<int, LL> pil;

const LL INF = 2e17 + 7;
const int Bit = 62;
const int MAXN = 2e5 + 7;

inline void proc_status() {
	ifstream t("/proc/self/status");
	cerr << string(istreambuf_iterator<char>(t), istreambuf_iterator<char>()) << endl;
}

template<typename T> inline T read() {
	T res = 0, flag = 1; char in = getchar();
	while(!isdigit(in)) { if(in == '-') flag = -1; in = getchar(); }
	while(isdigit(in)) { res = (res << 1) + (res << 3) + in - '0'; in = getchar(); }
	return res * flag;
}

template<typename T> inline void chkmax(T &a, T b) { if(a < b) a = b; }
template<typename T> inline void chkmin(T &a, T b) { if(a > b) a = b; }

LL by;
LL S, L, R;
int mul[Bit + 1];
int dp[Bit + 1][3][2][2];

int dfs(int k, int rest, bool bl, bool br) {
	if(k == -1) { return rest == 0; }
	int &res = dp[k][rest][bl][br];
	if(res >= 0) return res;
	res = 0;
	int l = 0, r = 1;
	if(bl) l = (L >> k) & 1;
	if(br) r = (R >> k) & 1;
	for(int i = l; i <= r; ++i) {
		if((!((S >> k) & 1)) && i) continue;
		res ^= dfs(k - 1, (rest - i * mul[k] + 3) % 3, bl && (i == l), br && (i == r));
	}
	return res;
}

inline int Val(int res, LL a, LL b, LL l, LL r) {
//	cout << r << endl;
	chkmax(l, a); chkmin(r, a + b);
//	exit(0);
	if(l > r) return 0;
	l -= a; r -= a;
	L = l; R = r; S = b;
//	printf("%lld %lld %lld %lld\n", a, b, l, r);
	memset(dp, -1, sizeof dp);
//	exit(0);
	a = (a % 3 + 3) % 3;
	return dfs(Bit, (res - a + 3) % 3, 1, 1);
}

int n;
pll p[MAXN];

inline bool IsOdd(LL l, LL r) {
	for(int i = 0; i < 3; ++i) {
		int res = 0;
		for(int j = 1; j <= n; ++j) {
//			cout << "GG " << p[j].x << ' ' << p[j].y << endl;
			int x = Val(i, p[j].x, p[j].y, l, r);
//			printf("FF %d\n", x);
//			exit(0);
			res ^= x;
		}
		if(res) return 1;
//		cout << res << endl;
//		exit(0);
	}
	return 0;
}

inline LL GetSt(LL l, LL r) {
//	cout << IsOdd(1, 3);
//	exit(0);
	while(1) {
//		cout << l << ' ' << r << endl;
		LL mid = l + r >> 1;
		if(IsOdd(l, mid)) r = mid;
		else l = mid + 1;
		if(l == r) return l;
	}
	exit(0);
}

LL st;

inline void init() {
	mul[0] = 1;
	for(int i = 1; i <= Bit; ++i) mul[i] = mul[i - 1] * 2 % 3;
	n = read<int>();
	by = LLONG_MAX;
	for(int i = 1; i <= n; ++i) {
		p[i].x = read<LL>();
		chkmin(by, p[i].y = read<LL>());
	}
	for(int i = 1; i <= n; ++i) p[i].y = p[i].y - by;

//	cout << GetSt(35408917861648745, 35408917861648746);
//	exit(0);

	st = GetSt(-INF, INF);
//	exit(0);
//	cout << st << endl;
//	printf("%lld\n", by);
}

inline int Val(LL x) {
	int res = 0;
	for(int i = 1; i <= n; ++i) {
		if(x < p[i].x) continue;
		if(x > p[i].x + p[i].y) continue;
		LL tx = x - p[i].x;
		res ^= ((tx & p[i].y) == tx);
//		printf("%d\n", res);
	}
	return res;
}

inline void solve() {
//	cout << Val(1) << endl;
//	cout << endl;
//	cout << st << endl;
//	cout << endl;
//	exit(0);
	LL ed = st;

//	cout << st << ' ' << ed << endl;
//	exit(0);

//	cout << (1ll << Bit) << endl;
	for(int i = Bit; i >= 0; --i) {
		if(Val(st - (1ll << i))) {
			st -= (1ll << i);
	//		cout << (1ll << i) << endl;
	//		exit(0);
		}
	}

	for(int i = Bit; i >= 0; --i) {
		if(Val(ed + (1ll << i))) {
//			exit(0);
			ed += (1ll << i);
		}
	}
//	exit(0);
	printf("%lld %lld\n", st, by + ed - st);
}

int main() {

	init();
	solve();

	return 0;
}



Measured memory_bytes: 512