//by yjz
#include<bits/stdc++.h>
using namespace std;
#define FF first
#define SS second
#define PB push_back
#define MP make_pair
#define foreach(it,s) for(__typeof((s).begin()) it=(s).begin();it!=(s).end();it++)
#ifndef LOCAL
#define cerr if(0)cout
#endif
typedef long long ll;
const int mod = 1e9+7;
//My i/o stream
struct fastio
{
	char s[100000];
	int it, len;
	fastio() {it=len=0;}
	inline char get()
	{
		if (it<len) return s[it++]; it=0;
		len=fread(s, 1, 100000, stdin);
		if (len==0) return EOF; else return s[it++];
	}
	bool notend()
	{
		char c=get();
		while (c==' '||c=='\n') c=get();
		if (it>0) it--;
		return c!=EOF;
	}
}_buff;
#define geti(x) x=getnum()
#define getii(x,y) geti(x),geti(y)
#define getiii(x,y,z) getii(x,y),geti(z)
#define puti(x) putnum(x),putchar(' ')
#define putii(x,y) puti(x),puti(y)
#define putiii(x,y,z) putii(x,y),puti(z)
#define putsi(x) putnum(x),putchar('\n')
#define putsii(x,y) puti(x),putsi(y)
#define putsiii(x,y,z) putii(x,y),putsi(z)
inline ll getnum()
{
	ll r=0; bool ng=0; char c; c=_buff.get();
	while (c!='-'&&(c<'0'||c>'9')) c=_buff.get();
	if (c=='-') ng=1, c=_buff.get();
	while (c>='0'&&c<='9') r=r*10+c-'0', c=_buff.get();
	return ng?-r:r;
}
template <class T> inline void putnum(T x)
{
	if (x<0) putchar('-'), x=-x;
	register short a[20]={}, sz=0;
	while (x) a[sz++]=x%10, x/=10;
	if(sz==0) putchar('0');
	for (int i=sz-1; i>=0; i--) putchar('0'+a[i]);
}
inline char getreal() {char c=_buff.get(); while (c<=32) c=_buff.get(); return c;}
ll qpow(ll x, ll k) {return k==0? 1: 1ll*qpow(1ll*x*x%mod,k>>1)*(k&1?x:1)%mod;}
const ll L = -2e17;
int n;
vector<pair<ll,ll> > v;
bool check_point(pair<ll,ll> p, ll x, ll y)
{
	ll X = x-p.FF;
	ll Y = p.SS-y;
	assert(Y>=0);
	if (X<0||X>Y) return false;
	return (Y&X)==X;
}
bool check_point(ll x)
{
	bool ret = 0;
	for (auto p : v)
	{
		if (check_point(p, x, L))
		{
			ret ^= 1;
		}
	}
	return ret;
}
bool cnt[3];
void calc(pair<ll,ll> p, ll x, ll y)
{
	ll X = x-p.FF;
	ll Y = p.SS-y;
	assert(Y>=0);
	if (X<0) return;
	if (X>Y) X = Y;
//	cerr<<X<<","<<Y<<endl;
	assert(Y>=0);
	static bool dp[66][2][3];
	memset(dp, 0, sizeof(dp));
	dp[61][1][0] = 1;
	for (int i=60; i>=0; i--)
	{
		for (int t=0; t<2; t++)
		{
			for (int v=0; v<2; v++)
			{
				if (v&&!((Y>>i)&1)) continue;
				if (v&&t&&!((X>>i)&1)) continue;
				int dlt = ((1ll*v)<<i)%3;
				int nt = t&(v==((X>>i)&1));
				for (int j=0; j<3; j++) dp[i][nt][(j+dlt)%3] ^= dp[i+1][t][j];
			}
		}
	}
	int t = ((p.FF%3)+3)%3;
//	for (int i=0; i<3; i++) cerr<<dp[0][0][i]; cerr<<" ";
//	for (int i=0; i<3; i++) cerr<<dp[0][1][i]; cerr<<endl;
	
	for (int i=0; i<3; i++)
	{
		cnt[(i+t)%3] ^= dp[0][0][i];
		cnt[(i+t)%3] ^= dp[0][1][i];
	}
}
bool check(ll x)
{
//	cerr<<"check:"<<x<<endl;
	cnt[0] = cnt[1] = cnt[2] = 0;
	for (auto p : v)
	{
		calc(p, x, L);
	}
//	cerr<<cnt[0]<<" "<<cnt[1]<<" "<<cnt[2]<<endl;
	return cnt[0]||cnt[1]||cnt[2];
}
int main()
{
	geti(n);
	for (int i=1; i<=n; i++)
	{
		ll x, y;
		getii(x, y);
		v.PB(MP(x, y));
	}
/*	for (int i=L; i<=-L; i++)
	{
		cerr<<check_point(i);
		if ((i-L)%5==0) cerr<<" ";
	} cerr<<endl;
*/
	ll l = -1e18, r = 1e18;
	while (l<=r)
	{
		ll m = l+r>>1;
		if (check(m)) r = m-1; else l = m+1;
	}
//	cerr<<l<<","<<r<<" "<<check(l)<<check(r)<<endl;
	r = l;
	assert(check_point(l));
//	cerr<<"l="<<l<<" r="<<r<<endl;
	for (int i=60; i>=0; i--) if (check_point(l-(1ll<<i))) l -= 1ll<<i;
	for (int i=60; i>=0; i--) if (check_point(r+(1ll<<i))) r += 1ll<<i;
//	cerr<<l<<","<<r<<endl;

	cout<<l<<" "<<L+(r-l)<<endl;
	return 0;
}


Measured memory_bytes: 768