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>
#pragma GCC optimize ("O2")
#pragma GCC optimize ("unroll-loops")
//#pragma GCC optimize("no-stack-protector,fast-math")

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<pii, int> piii;
typedef pair<ll, ll> pll;
#define debug(x) cerr<<#x<<'='<<(x)<<endl;
#define debugp(x) cerr<<#x<<"= {"<<(x.first)<<", "<<(x.second)<<"}"<<endl;
#define debug2(x, y) cerr<<"{"<<#x<<", "<<#y<<"} = {"<<(x)<<", "<<(y)<<"}"<<endl;
#define debugv(v) {cerr<<#v<<" : ";for (auto x:v) cerr<<x<<' ';cerr<<endl;}
#define all(x) x.begin(), x.end()
#define pb push_back
#define kill(x) return cout<<x<<'\n', 0;

const ld eps=1e-7;
const int inf=1000000010;
const ll INF=10000000000000010LL;
const int mod=1000000007;
const int MAXN=10010, MAXM=1000000;

int n, m, k, u, v, x, y, t, a, b, ans;
int X[MAXN], Y[MAXN];
pii A[MAXN<<1];
bool mark[MAXM];
int comp[MAXM], cid;
int seg[MAXN<<3], N;
vector<int> G[MAXM], GR[MAXM], topol;

void add_edge(int u, int v){
	G[u].pb(v);
	GR[v].pb(u);
}

void add_clause(int u, int v){
	add_edge(u^1, v);
	add_edge(v^1, u);
}

void Set(int id, int tl, int tr, int pos, int val){
	if (pos<tl || tr<=pos) return ;
	if (tr-tl==1){
		seg[id]=val;
		return ;
	}
	int mid=(tl+tr)>>1;
	Set(id<<1, tl, mid, pos, val);
	Set(id<<1 | 1, mid, tr, pos, val);
	if (seg[id<<1]!=-1 && seg[id<<1 | 1]!=-1){
		seg[id]=(N++)<<1;
		add_clause(seg[id<<1]^1, seg[id]);
		add_clause(seg[id<<1 | 1]^1, seg[id]);
		add_clause(seg[id<<1]^1, seg[id<<1 | 1]^1);
	}
	else seg[id]=seg[id<<1]+seg[id<<1 | 1]+1;
}

void Add(int pos){
	Set(1, 0, n<<1, pos, pos);
}
void Rem(int pos){
	Set(1, 0, n<<1, pos, -1);
}

void dfs1(int node){
	mark[node]=1;
	for (int v:G[node]) if (!mark[v]) dfs1(v);
	topol.pb(node);
}

void dfs2(int node, int cid){
	comp[node]=cid;
	for (int v:GR[node]) if (!comp[v]) dfs2(v, cid);
}

bool check(int val){
	for (int i=0; i<2*N; i++){
		mark[i]=0;
		comp[i]=0;
		G[i].clear();
		GR[i].clear();
	}
	N=n;
	cid=0;
	topol.clear();
	memset(seg, -1, sizeof(seg));
	int j=0;
	for (int i=0; i<2*n; i++){
		while (A[i].first-A[j].first>=val) Rem(A[j++].second);
		Add(A[i].second);
	}
	for (int i=0; i<2*N; i++) if (!mark[i]) dfs1(i);
	reverse(all(topol));
	for (int v:topol) if (!comp[v]) dfs2(v, ++cid);
	for (int i=0; i<N; i++) if (comp[i<<1]==comp[i<<1 | 1]) return 0;
	return 1;
}

int main(){
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	cin>>n;
	for (int i=0; i<n; i++){
		cin>>X[i]>>Y[i];
		A[i<<1]={X[i], i<<1};
		A[i<<1 | 1]={Y[i], i<<1 | 1};
	}
	sort(A, A+2*n);
	int dwn=0, up=1000000000;
	while (up-dwn>1){
		int mid=(dwn+up)>>1;
		if (check(mid)) dwn=mid;
		else up=mid;
	}
	cout<<dwn<<'\n';
	
	return 0;
}