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++ (GCC 9.2.1) (judge verdict: Accepted)

#pragma GCC optimize(3)
#pragma GCC optimize(2)
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define mkp make_pair
#define rint register int
#define INF ((1 << 30) - 1)
#define FI(n) FastIO::read(n)
#define FO(n) FastIO::write(n)
#define Pair pair < int, int >
#define mst(a,b) memset(a,b,sizeof(a))
#define foR(i, k, j) for(rint i = (k); i >= (j); i--)
#define For(i, k, j) for(rint i = (k); i <= (j); i++)
#define Foe(i, u) for(rint i = lst[u], v = e[i].v; i; i = e[i].nxt, v = e[i].v)
#define IOS ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define file(s) freopen(s".in", "r", stdin); freopen(s".out", "w", stdout)
#define ull unsigned ll
const int P = 998244353; //
using namespace std;
inline void ckmax(int &a, int b) {a = max(a, b);}
inline void ckmin(int &a, int b) {a = min(a, b);}
inline void mulmod(int &a, int b) {a = 1ll * a * b % P;}
inline void addmod(int &a, int b) {int t = a + b; a = (t >= P ? t - P : t); }
inline int ksm(int a, int b) {int ans=1; for(;b;b>>=1) {if(b&1) ans=1ll*ans*a%P;a=1ll*a*a%P;}return ans;}
inline int inv(int a) {return ksm(a, P-2);}

inline void printarray(int *a, int n) {For(i, 1, n) fprintf(stderr, "%d ", a[i]); fprintf(stderr, "\n");}
namespace FastIO {
    const int SIZE=1<<16; char buf[SIZE], obuf[SIZE], str[64]; int bi=SIZE, bn=SIZE, opt;
    int read(char *s) {
        while (bn) {for (;bi<bn&&buf[bi]<=' ';bi++);if (bi<bn) break; bn=fread(buf,1,SIZE,stdin),bi=0;}
        int sn=0;while (bn) {for (;bi<bn&&buf[bi]>' ';bi++) s[sn++]=buf[bi];if (bi<bn) break; bn=fread(buf,1,SIZE,stdin),bi=0;}s[sn]=0;return sn;
    }
    bool read(int& x) {if(x)x=0;int bf=0,n=read(str); if(!n) return 0; int i=0; if (str[i]=='-') bf=1,i=1; for(x=0;i<n;i++) x=x*10+str[i]-'0'; if(bf) x=-x; return 1;}
    void write(int x) {
        if(!x) obuf[opt++] = '0'; else {if(x<0) obuf[opt++]='-',x=-x;int sn=0; while(x)str[sn++]=x%10+'0',x/=10;for (int i=sn-1;i>=0;i--) obuf[opt++]=str[i];}
        if (opt>=(SIZE>>1)){fwrite(obuf, 1, opt, stdout); opt=0;}
    }
    void write(char x) {obuf[opt++]=x;if (opt>=(SIZE>>1)){fwrite(obuf, 1, opt, stdout); opt=0;}}
    void Fflush() { if (opt) fwrite(obuf, 1, opt, stdout); opt=0;}
};
const int MAXN = 2e4 + 5;
const int N = MAXN * 13;
int n, ano[MAXN], pos[MAXN][2];
Pair a[MAXN];
#define ls (k << 1)
#define rs (k << 1 | 1)
#define mid ((l + r) >> 1)
vector < int > e[N];
void build(int k, int l, int r) {
	if(l == r) return e[k + 2 * n].pb(ano[l]);
	e[k + 2 * n].pb(ls + 2 * n), e[k + 2 * n].pb(rs + 2 * n); build(ls, l, mid); build(rs, mid+1, r);
}
void add(int k, int l, int r, int id, int ql, int qr) {
	if(ql > qr) return;
	if(l == ql && r == qr) return e[id].pb(k + 2 * n);
	if(qr <= mid) add(ls, l, mid, id, ql, qr);
	else if(mid < ql) add(rs, mid+1, r, id, ql, qr);
	else add(ls, l, mid, id, ql, mid), add(rs, mid+1, r, id, mid+1, qr);
}
#undef mid
int dfn[N], low[N], s[N], top = 0, ins[N], col[N], cnt, ind;
void tarjan(int u) {
	dfn[u] = low[u] = ++ind; s[++top] = u, ins[u] = 1;
	for(int i = 0; i < e[u].size(); i++) {
		int v = e[u][i];
		if(!dfn[v]) {
			tarjan(v); ckmin(low[u], low[v]);
		} else if(ins[v]) {
			ckmin(low[u], low[v]);
		}
	}
	if(low[u] == dfn[u]) {
		++cnt;
		while(s[top] != u) ins[s[top]] = 0, col[s[top--]] = cnt;
		ins[s[top]] = 0, col[s[top--]] = cnt;
	}
}
bool check(int mid) {
//	cerr << mid << endl;
	ind = 0; cnt = 0; For(i, 1, 12 * n) e[i].clear(), dfn[i] = low[i] = 0; build(1, 1, 2 * n); 
	For(i, 1, 2 * n) {
		int l = lower_bound(a + 1, a + 1 + 2 * n, mkp(a[i].first - mid + 1, -INF)) - a,
		    r = upper_bound(a + 1, a + 1 + 2 * n, mkp(a[i].first + mid - 1, INF)) - a - 1;
		int t1 = ano[i], t2 = i; if(t1 > t2) swap(t1, t2);
		
//		if(mid <= 10) cerr << i << ' ' << l << ' ' << r << ' ' << t1 << ' ' << t2 << endl;
		add(1, 1, 2 * n, i, l, t1 - 1);
		add(1, 1, 2 * n, i, max(l, t1 + 1), min(r, t2 - 1));
		add(1, 1, 2 * n, i, t2 + 1, r);
	}
	For(i, 1, 12 * n) if(!dfn[i]) tarjan(i);
//	if(mid <= 10) {
//		For(i, 1, 12 * n) cerr << col[i] << ' ';
//		cerr << endl;
//		For(i, 1, n) cerr << pos[i][0] << ' ' << pos[i][1] << endl;
//		cerr << endl << endl;
//	}
	For(i, 1, n) if(col[pos[i][0]] == col[pos[i][1]]) return 0;
	return 1;
}
signed main()
{
    #ifndef ONLINE_JUDGE
        file("pro");
    #endif
	FI(n);
	For(i, 1, n) {
		int x, y; FI(x); FI(y);
		a[i*2-1] = mkp(x, i), a[i*2] = mkp(y, i);
	}
	sort(a + 1, a + 1 + n * 2);
	For(i, 1, n * 2) {
		if(!pos[a[i].second][0]) pos[a[i].second][0] = i;
		else pos[a[i].second][1] = i;
	}
//	For(i, 1, n) cerr << pos[i][0] << ' ' << pos[i][1] << endl;
//	cerr << endl << endl;
	For(i, 1, n) ano[pos[i][0]] = pos[i][1], ano[pos[i][1]] = pos[i][0];
	int l = 0, r = 1e9, res = -1;
	while(l <= r) {
//		cerr << l << ' ' << r  << endl;
		int mid = (l + r) >> 1;
		if(check(mid)) {
			res = mid, l = mid + 1;
		} else r = mid - 1;
	}
	cout << res << endl;
    return FastIO::Fflush(), 0;
}
/*
Think twice :
mod ?
INF ?
n = 1 ?
long long ?
Fastio::Fflush() ?
*/