Problem:
Score : 1000 points

Problem Statement

There is an infinitely large triangular grid, as shown below.
Each point with integer coordinates contains a lamp.

Initially, only the lamp at (X, 0) was on, and all other lamps were off.
Then, Snuke performed the following operation zero or more times:

Choose two integers x and y.
Toggle (on to off, off to on) the following three lamps: (x, y), (x, y+1), (x+1, y).

After the operations, N lamps (x_1, y_1), \cdots, (x_N, y_N) are on, and all other lamps are off.
Find X.

Constraints

1 \leq N \leq 10^5

-10^{17} \leq x_i, y_i \leq 10^{17}

(x_i, y_i) are pairwise distinct.

The input is consistent with the statement, and you can uniquely determine X.

Input

Input is given from Standard Input in the following format:

N
x_1 y_1
:
x_N y_N

Output

Print X.

Sample Input 1

4
-2 1
-2 2
0 1
1 0

Sample Output 1

-1

The following picture shows one possible sequence of operations:

Solution in C++14 (GCC 5.4.1) (judge verdict: Time Limit Exceeded)

#include<iostream>
using namespace std;
typedef long long ll;
int n;
ll x[100001],y[100001];
ll tae(ll x,ll y){//y<2^59
	ll eq=1,sm=0,neq,nsm;
	for(int i=58; i>=0 ;i--){
		neq=nsm=0;
		if((x&(1LL<<i))!=0){
			if((y&(1LL<<i))==0) nsm+=eq;
			else neq+=eq,nsm+=eq;
		}
		else neq+=eq;
		if((y&(1LL<<i))==0) nsm+=sm;
		else nsm+=2*sm;
		eq=neq,sm=nsm;
	}
	/*int ext=0;
	for(ll i=0; i<=x ;i++) if((i&y)==i) ext++;
	cout << ext << endl;*/
	return (eq+sm)%2;
}
int qry(ll l,ll r){
	int sum=0;
	for(int i=1; i<=n ;i++){
		ll ty=y[i]+(1LL<<58);
		ll xl=x[i],xr=x[i]+ty;
		xl=max(xl,l);
		xr=min(xr,r);
		if(xl>xr) continue;
		sum^=tae(xr-x[i],ty)%2;
		if(xl!=x[i]) sum^=tae(xl-x[i]-1,ty)%2;
	}
	return sum;
}
int main(){
	ios::sync_with_stdio(false);
	cin >> n;
	for(int i=1; i<=n ;i++){
		cin >> x[i] >> y[i];
	}
	ll l=-1e17,r=1e17;
	while(l!=r){
		ll mid=l+(r-l)/2;
		int sum=qry(l,mid);
		if(sum%2==0) l=mid+1;
		else r=mid;
	}
	cout << l << endl;
}