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: Time Limit Exceeded)

#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)
typedef long long ll;

const ll INF=1e9;
const int MAX_N=1e5;

int N,X[MAX_N],Y[MAX_N];

vector<int> G[MAX_N*2],rG[MAX_N*2];

vector<int> vs;
int cmp[MAX_N*2];
bool used[MAX_N*2];

void add_edge(int from,int to){
	G[from].push_back(to);
	rG[to].push_back(from);
}

void dfs(int v){
	used[v]=true;
	REP(i,G[v].size()){
		if (!used[G[v][i]]){
			dfs(G[v][i]);
		}
	}
	vs.push_back(v);
}

void rdfs(int v,int k){
	used[v]=true;
	cmp[v]=k;
	REP(i,rG[v].size()){
		if (!used[rG[v][i]]){
			rdfs(rG[v][i],k);
		}
	}
}

int scc(){
	memset(used,0,sizeof(used));
	vs.clear();
	REP(i,N*2){
		if (!used[i]){
			dfs(i);
		}
	}
	memset(used,0,sizeof(used));
	int k=0;
	reverse(vs.begin(),vs.end());
	REP(i,(int)vs.size()){
		if (!used[vs[i]]){
			rdfs(vs[i],k++);
		}
	}
	return k;
}

bool C(ll d){
	REP(i,2*N){
		G[i].clear();
		rG[i].clear();
	}
	REP(i,N){
		FOR(j,i+1,N){
			if (i!=j){
				if (abs(X[i]-X[j])<d){
//					G[i].push_back(j+N);
//					G[j].push_back(i+N);
					add_edge(i,j+N);
					add_edge(j,i+N);
				}
				if (abs(X[i]-Y[j])<d){
//					G[i].push_back(j);
//					G[j+N].push_back(i+N);
					add_edge(i,j);
					add_edge(j+N,i+N);
				}
				if (abs(Y[i]-X[j])<d){
//					G[i+N].push_back(j+N);
	//				G[j].push_back(i);
					add_edge(i+N,j+N);
					add_edge(j,i);
				}
				if (abs(Y[i]-Y[j])<d){
		//			G[i+N].push_back(j);
			//		G[j+N].push_back(i);
					add_edge(i+N,j);
					add_edge(j+N,i);
				}
			}
		}
	}
	scc();
	REP(i,N){
		if (cmp[i]==cmp[i+N]){
			return false;
		}
	}
	return true;
}

int main(){
	scanf("%d",&N);
	REP(i,N){
		scanf("%d %d",&X[i],&Y[i]);
	}
	ll lb=0,ub=INF;
	while(ub-lb>1){

		ll mid=(lb+ub)>>2;
		if (C(mid)){
			lb=mid;
		}else{
			ub=mid;
		}
	}
	printf("%lld\n",lb);
	return 0;
}