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>
#define mem(a,b) memset(a,b,sizeof(a))
#define  For(i,a,b) for(int i=a,i##E=b;i<=i##E;++i)
#define rFor(i,a,b) for(int i=a,i##E=b;i>=i##E;--i)
typedef long long LL;
using namespace std;
const int N=20010;
const int M=40000010;
const int inf=0x3f3f3f3f;
template<typename T>inline bool chkmin(T &a,const T &b){return a>b?a=b,1:0;}
template<typename T>inline bool chkmax(T &a,const T &b){return a<b?a=b,1:0;}
template<typename T>inline void read(T &x)
{
	x=0;int _f(0);char ch=getchar();
	while(!isdigit(ch))_f|=(ch=='-'),ch=getchar();
	while( isdigit(ch))x=x*10+ch-'0',ch=getchar();
	x=_f?-x:x;
}
inline void file()
{
	freopen("A.in","r",stdin);
	freopen("A.out","w",stdout);
}
int n,cnt;
int x[N],y[N];
int bgn[N],nxt[M],to[M],E;
int dfn[N],low[N],dfs_time;
int bel[N],st[N],top,in[N];
int scc_cnt;
struct node
{
	int pos,id,type;
	node(){}
	node(int pos,int id,int type):pos(pos),id(id),type(type){}
}a[N];
inline bool operator<(node A,node B){return A.pos<B.pos;}
inline void add_edge(int u,int v)
{
	//printf("%d %d\n",u,v);
	nxt[++E]=bgn[u],bgn[u]=E,to[E]=v;
}
inline void dfs(int u)
{
	dfn[u]=low[u]=++dfs_time;
	in[st[++top]=u]=1;
	for(int v,i=bgn[u];i;i=nxt[i])
	{
		if(!dfn[v=to[i]])
		{
			dfs(v);
			chkmin(dfn[u],low[v]);
		}
		else if(in[v])chkmin(dfn[u],dfn[v]);
	}
	if(low[u]==dfn[u])
	{
		++scc_cnt;
		int x;
		do
		{
			x=st[top--];
			in[x]=0;
			bel[x]=scc_cnt;
		}while(x!=u);
	}
}
inline bool check(int x)
{
	mem(dfn,0);
	mem(bgn,0);
	mem(bel,0);
	E=0;
	scc_cnt=0;
	dfs_time=0;
	int nowl=1,nowr=1;
	For(i,1,cnt)
	{
		while(nowl<cnt&&a[nowl].pos<=a[i].pos-x)nowl++;
		while(nowr<cnt&&a[nowr+1].pos<a[i].pos+x)nowr++;
		For(j,max(i-10,nowl),i)
		if(i!=j)
		{
			add_edge(a[i].id*2+a[i].type,a[j].id*2+(a[j].type^1));
			add_edge(a[j].id*2+a[j].type,a[i].id*2+(a[i].type^1));
		}
		For(j,i,min(i+10,nowr))
		if(i!=j)
		{
			add_edge(a[i].id*2+a[i].type,a[j].id*2+(a[j].type^1));
			add_edge(a[j].id*2+a[j].type,a[i].id*2+(a[i].type^1));
		}
	}
	For(i,1,n)
	{
		if(!dfn[i*2])dfs(i*2);
		if(!dfn[i*2+1])dfs(i*2+1);
	}
	For(i,1,n)if(bel[i*2]==bel[i*2+1])return 0;
	return 1;
}
int main()
{
	read(n);
	int MAX=0;
	For(i,1,n)
	{
		read(x[i]),read(y[i]);
		a[++cnt]=node(x[i],i,0);
		a[++cnt]=node(y[i],i,1);
		chkmax(MAX,x[i]),chkmax(MAX,y[i]);
	}
	sort(a+1,a+cnt+1);
	int l=1,r=MAX/(n-1),ans=0;
	while(l<=r)
	{
		int mid=(l+r)>>1;
		if(check(mid))ans=mid,l=mid+1;
		else r=mid-1;
	}
	printf("%d\n",ans);
	return 0;
}