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: Wrong Answer)

#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<algorithm>
//#include<ctime>

namespace fuck
{
	inline int abs(int x){return x<0?-x:x;}
	template<typename T>inline bool check_min(T a,T &b){return a<b?b=a,1:0;}
	template<typename T>inline bool check_max(T a,T &b){return a>b?b=a,1:0;}
	typedef std::vector<int>::iterator vit;

	struct node
	{
		int x,id;
		node (int a=0,int b=0){x=a,id=b;}
		bool operator < (const node &h) const {return x<h.x;}
	};

	const int N=10010,M=N*2;

	std::vector<int> G[M];
	node s[M];

	int n,m,lim;
	inline void add(int x,int y){G[x].push_back(y);}

#define id(i) (n+i)
#define dec(i) (i>n?i-n:i+n)

	int ins[M],stk[M];
	int col[M],dfn[M];
	int clk,tot,top;

	int tarjan(int p)
	{
		stk[++top]=p,ins[p]=1;
		int lowp=dfn[p]=++clk,lowq;
		for(vit it=G[p].begin();it!=G[p].end();it++)
		{
			int q=*it;
			if(dfn[q])
			{
				if(ins[q])check_min(dfn[q],lowp);
				continue;
			}
			check_min(lowq=tarjan(q),lowp);
		}

		if(lowp==dfn[p])
		{
			tot++;
			for(int x;;)
			{
				x=stk[top--];
				ins[x]=0;
				col[x]=tot;
				if(x==p)break;
			}
		}

		return lowp;
	}

	bool check()
	{
		static bool sel[M];
		static int his[M],cnt;

		for(int i=1;i<=n;i++)G[i].clear(),G[i+n].clear();

		memset(sel,0,sizeof(sel));
		for(int i=1;i<=m;i++)
		{
			cnt=0;
			int L=i-1,R=i+1,p=s[i].id,q;
			while(R<=m && s[R].x-s[i].x<lim)
			{
				if(sel[s[R].id])break;
				q=dec(s[R].id);
				add(p,q);

				sel[q]=1;
				his[++cnt]=q;
				R++;
			}
			while(L>=1 && s[i].x-s[L].x<lim)
			{
				if(sel[s[L].id])break;
				q=dec(s[L].id);
				add(p,q);

				sel[q]=1;
				his[++cnt]=q;
				L--;
			}
			for(int j=1;j<=cnt;j++)
				sel[his[j]]=0;

			cnt=0;
		}

		for(int i=1;i<=m;i++)
			ins[i]=col[i]=dfn[i]=0;
		top=clk=tot=0;
		
		for(int i=1;i<=m;i++)
			if(!dfn[i])tarjan(i);

		for(int i=1;i<=n;i++)
			if(col[i]==col[id(i)])return 0;
		return 1;
	}

	void initialize()
	{
		scanf("%d",&n),m=0;
		for(int i=1,x,y;i<=n;i++)
		{
			scanf("%d%d",&x,&y);
			s[++m]=node(x,i);
			s[++m]=node(y,id(i));
		}
		std::sort(s+1,s+m+1);
	}
	void solve()
	{
		initialize();
		int u=1000000000,d=0;
		while(u>d)
		{
//			fprintf(stderr,"%d--%d\n",d,u);
			lim=(u+d+1)>>1;
			if(check())d=lim;
			else u=lim-1;
		}
		printf("%d\n",d);
	}
}

int main()
{
	fuck::solve();

//	fprintf(stderr,"my time = %lf\n",(double)clock()/CLOCKS_PER_SEC);
	return 0;
}