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: Accepted)

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

using ll=long long;
#define int ll

#define FOR(i,a,b) for(int i=int(a);i<int(b);i++)
#define REP(i,b) FOR(i,0,b)
#define MP make_pair
#define PB push_back
#define ALL(x) x.begin(),x.end()
#define REACH cerr<<"reached line "<<__LINE__<<endl
#define DBG(x) cerr<<"line "<<__LINE__<<" "<<#x<<":"<<x<<endl

using pi=pair<int,int>;
using vi=vector<int>;
using ld=long double;

template<class T,class U>
ostream& operator<<(ostream& os,const pair<T,U>& p){
	os<<"("<<p.first<<","<<p.second<<")";
	return os;
}

template<class T>
ostream& operator <<(ostream& os,const vector<T>& v){
	os<<"[";
	REP(i,(int)v.size()){
		if(i)os<<",";
		os<<v[i];
	}
	os<<"]";
	return os;
}

int read(){
	int i;
	scanf("%lld",&i);
	return i;
}

void printSpace(){
	printf(" ");
}

void printEoln(){
	printf("\n");
}

void print(int x,int suc=1){
	printf("%lld",x);
	if(suc==1)
		printEoln();
	if(suc==2)
		printSpace();
}

string readString(){
	static char buf[3341919];
	scanf("%s",buf);
	return string(buf);
}

char* readCharArray(){
	static char buf[3341919];
	static int bufUsed=0;
	char* ret=buf+bufUsed;
	scanf("%s",ret);
	bufUsed+=strlen(ret)+1;
	return ret;
}

template<class T,class U>
void chmax(T& a,U b){
	if(a<b)
		a=b;
}

template<class T,class U>
void chmin(T& a,U b){
	if(a>b)
		a=b;
}

template<class T>
T Sq(const T& t){
	return t*t;
}

const int inf=LLONG_MAX/3;

vi ord,low,ins,belong;
int ordIdx,cmpIdx;
void dfs(const vector<vi>& graph,int v,stack<int>& s){
	s.push(v);
	ord[v]=low[v]=ordIdx++;
	ins[v]=1;
	for(auto to:graph[v])
		if(ord[to]==-1){
			dfs(graph,to,s);
			chmin(low[v],low[to]);
		}else if(ins[to])
			chmin(low[v],ord[to]);
	if(ord[v]==low[v]){
		while(1){
			int g=s.top();s.pop();
			belong[g]=cmpIdx;
			ins[g]=0;
			if(g==v)break;
		}
		cmpIdx++;
	}
}
void BuildSCC(const vector<vi>& graph){
	int n=graph.size();
	ord.assign(n,-1);
	low.assign(n,-1);
	ins.assign(n,0);
	belong.assign(n,-1);
	stack<int> s;
	ordIdx=0,cmpIdx=0;
	REP(i,n)if(ord[i]==-1)
		dfs(graph,i,s);
}

struct Flag{
	int x,y;
};
struct Snuke{
	int v,i,t;
	bool operator<(const Snuke& rhs)const{
		if(v!=rhs.v)return v<rhs.v;
		else if(i!=rhs.i)return i<rhs.i;
		else return t<rhs.t;
	}
};

void SetEdge(vector<vi>& graph,int b,int e,int l,int r,int i,int from){
	if(e<=b)return;
	if(e<=l||r<=b)return;
	if(b<=l&&r<=e)return void(graph[from].PB(i));
	SetEdge(graph,b,e,l,(l+r)/2,i*2,from);
	SetEdge(graph,b,e,(l+r)/2,r,i*2+1,from);
}

bool Wafrelka(const int n,const vector<Flag>& fs,const vector<Snuke>& ss,const int d){
	int s=1;
	while(s<n*2)s*=2;
	vector<vi> graph(s*2);
	FOR(i,1,s){
		graph[i].PB(i*2);
		graph[i].PB(i*2+1);
	}
	REP(i,n){
		int xi=lower_bound(ALL(ss),Snuke{fs[i].x,i,1})-ss.begin();
		int yi=lower_bound(ALL(ss),Snuke{fs[i].y,i,2})-ss.begin();
		{
			int b=lower_bound(ALL(ss),Snuke{fs[i].x-d+1,-inf,0})-ss.begin();
			int e=lower_bound(ALL(ss),Snuke{fs[i].x+d-1,inf,0})-ss.begin();
			SetEdge(graph,b,xi,0,s,1,yi+s);
			SetEdge(graph,xi+1,e,0,s,1,yi+s);
		}
		{
			int b=lower_bound(ALL(ss),Snuke{fs[i].y-d+1,-inf,0})-ss.begin();
			int e=lower_bound(ALL(ss),Snuke{fs[i].y+d-1,inf,0})-ss.begin();
			SetEdge(graph,b,yi,0,s,1,xi+s);
			SetEdge(graph,yi+1,e,0,s,1,xi+s);
		}
	}
	BuildSCC(graph);
	REP(i,n){
		int xi=lower_bound(ALL(ss),Snuke{fs[i].x,i,1})-ss.begin();
		int yi=lower_bound(ALL(ss),Snuke{fs[i].y,i,2})-ss.begin();
		if(belong[xi+s]==belong[yi+s])
			return false;
	}
	return true;
}

signed main(){
	int n=read();
	vector<Flag> fs;
	vector<Snuke> ss;
	REP(i,n){
		int x=read(),y=read();
		fs.PB(Flag{x,y});
		ss.PB(Snuke{x,i,1});
		ss.PB(Snuke{y,i,2});
	}
	sort(ALL(ss));
	int l=0,r=1000000000;
	while(r-l>1){
		const int mid=(r+l)/2;
		if(Wafrelka(n,fs,ss,mid))
			l=mid;
		else
			r=mid;
	}
	print(l);
}