Problem:
Score : 1200 points

Problem Statement

Snuke loves flags.

Snuke is placing N flags on a line.

The i-th flag can be placed at either coordinate x_i or coordinate y_i.

Snuke thinks that the flags look nicer when the smallest distance between two of them, d, is larger. Find the maximum possible value of d.

Constraints

2 ≤ N ≤ 10^{4}

1 ≤ x_i, y_i ≤ 10^{9}

x_i and y_i are integers.

Input

The input is given from Standard Input in the following format:

N
x_1 y_1
:
x_N y_N

Output

Print the answer.

Sample Input 1

3
1 3
2 5
1 9

Sample Output 1

4

The optimal solution is to place the first flag at coordinate 1, the second flag at coordinate 5 and the third flag at coordinate 9. The smallest distance between two of the flags is 4 in this case.

Sample Input 2

5
2 2
2 2
2 2
2 2
2 2

Sample Output 2

0

There can be more than one flag at the same position.

Sample Input 3

22
93 6440
78 6647
862 11
8306 9689
798 99
801 521
188 206
6079 971
4559 209
50 94
92 6270
5403 560
803 83
1855 99
42 504
75 484
629 11
92 122
3359 37
28 16
648 14
11 269

Sample Output 3

17

Solution in C++14 (GCC 5.4.1) (judge verdict: Runtime Error)

#include <bits/stdc++.h>
using namespace std;

typedef pair<int,int> P;

#define fr first
#define sc second

int n;
int x[1002],y[1002];

bitset<2002> G[1002];
bitset<2002> rG[1002];

vector<int> vs;
bitset<2002> alive;
bitset<2002> nex;
void dfs(int v){
	if(!alive[v])return;
	alive[v] = false;
	while(1){
		nex = alive & G[v];
		int x = nex._Find_first();
		if(x == 2002)break;
		dfs(x);
	}
	vs.push_back(v);
}

bitset<2002> c;
void scc(int v){
	if(!alive[v])return;
	alive[v] = false;
	while(1){
		nex = alive & rG[v];
		int x = nex._Find_first();
		if(x == 2002)break;
		scc(x);
	}
	c[v] = true;
}

bitset<2002> mask;

bool f(int d){
	vector<P> vec;
	for(int i = 0 ; i < n ; i ++){
		vec.push_back(P(x[i],2*i));
		vec.push_back(P(y[i],2*i+1));
	}
	sort(vec.begin(),vec.end());
	
	/*for(P p: vec){
		cout << p.fr << " " << p.sc << endl;
	}*/
	
	bitset<2002> a,b;
	int l = 0, r = 0;
	for(int i = 0 ; i < vec.size() ; i ++){
		while(r < vec.size() && vec[r].fr < vec[i].fr+d){
			a[vec[r].sc^1] = true;
			b[vec[r].sc] = true;
			r ++;
		}
		while(l < vec.size() && vec[l].fr <= vec[i].fr-d){
			a[vec[l].sc^1] = false;
			b[vec[l].sc] = false;
			l ++;
		}
		G[vec[i].sc] = a;
		G[vec[i].sc][vec[i].sc^1] = false;
		rG[vec[i].sc^1] = b;
		rG[vec[i].sc^1][vec[i].sc] = false;
		/*for(int j = 0 ; j < 2*n ; j ++){
			if(a[j])printf("1");
			else printf("0");
		}
		cout << endl;*/
	}
	//puts("=======");
	
	/*for(int i = 0 ; i < 2*n ; i ++){
		for(int j = 0 ; j < 2*n ; j ++){
			if(G[i][j])printf("1");
			else printf("0");
		}
		cout << endl;
	}
	puts("======");
	for(int i = 0 ; i < 2*n ; i ++){
		for(int j = 0 ; j < 2*n ; j ++){
			if(rG[i][j])printf("1");
			else printf("0");
		}
		cout << endl;
	}
	puts("======");*/
	
	vs.clear();
	alive.set();
	for(int i = 0 ; i < 2*n ; i ++){
		if(alive[i])dfs(i);
	}
	reverse(vs.begin(),vs.end());
	alive.set();
	for(int i = 0 ; i < vs.size() ; i ++){
		c.reset();
		scc(vs[i]);
		/*for(int j = 0 ; j < 2*n ; j ++){
			if(c[j])printf("1");
			else printf("0");
		}
		cout << endl;*/
		c &= c>>1;
		c &= mask;
		if(c.any())return false;
	}
	return true;
}

int main(){
	mask.reset();
	for(int i = 0 ; i < 1000 ; i ++){
		mask[2*i] = true;
	}
	
	scanf("%d",&n);
	for(int i = 0 ; i < n ; i ++){
		scanf("%d%d",&x[i],&y[i]);
	}
	
	//f(2);
	//return 0;
	
	int l = 0, r = 1000000000;
	while(l < r){
		int m = (l+r+1)/2;
		if(f(m))l = m;
		else r = m-1;
	}
	cout << l << endl;
}