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: Time Limit Exceeded)

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

#define int long long

const int inf = 1e18;

struct T {
	int val, sum, mn;
	int fix, siz;
	T *lson, *rson;
	T(int v) {
		val = sum = mn = v;
		fix = rand(); siz = 1;
		lson = rson = NULL;
	}
};

void del_T(T *&x) {
	if (x -> lson) del_T(x -> lson);
	if (x -> rson) del_T(x -> rson);
	delete x; x = NULL;
}

void pushup(T *x) {
	x -> sum = x -> val;
	if (x -> lson) x -> sum += x -> lson -> sum;
	if (x -> rson) x -> sum += x -> rson -> sum;
	x -> mn = x -> val;
	if (x -> lson) x -> mn = min(x -> mn, x -> lson -> mn);
	if (x -> rson) x -> mn = min(x -> mn, x -> rson -> mn);
	x -> siz = 1;
	if (x -> lson) x -> siz += x -> lson -> siz;
	if (x -> rson) x -> siz += x -> rson -> siz;
}

void split(T *x, int k, T *&a, T *&b) {
	if (!x) {a = b = NULL; return ;}
	int lsiz = x -> lson ? x -> lson -> siz : 0;
	if (lsiz + 1 <= k) {
		a = x;
		split(x -> rson, k - lsiz - 1, a -> rson, b);
		pushup(a);
	} else {
		b = x;
		split(x -> lson, k, a, b -> lson);
		pushup(b);
	}
}

T *merge(T *a, T *b) {
	if (!a || !b) return a ? a : b;
	if (a -> fix < b -> fix) {
		a -> rson = merge(a -> rson, b);
		pushup(a);
		return a;
	} else {
		b -> lson = merge(a, b -> lson);
		pushup(b);
		return b;
	}
}

int find(T *x, int v) {
	int lsum = x -> lson ? x -> lson -> sum : 0;
	int lsiz = x -> lson ? x -> lson -> siz : 0;
	if (lsum >= v) return find(x -> lson, v);
	if (lsum + x -> val >= v) return 1 + lsiz;
	return 1 + lsiz + find(x -> rson, v - lsum - x -> val);
}

T *root;

void prt(T *x) {
	if (!x) return ;
	prt(x -> lson);
	cerr << x -> val << " ";
	prt(x -> rson);
}

void wait() {for (int i = 0; i < 1e8; ++ i) i <<= 1, i >>= 1;}
#define dbg(x) {cerr << #x << ": "; prt(x); cerr << endl; wait();}

const int N = 1e4 + 5;
int n, x[N][2], use[N];
int cur;

void del(int k) {
	// cerr << "del " << k << endl;
	T *a, *b, *c;
	int rnk = find(root, x[k][use[k]] + inf);
	split(root, rnk + 1, b, c);
	split(b, rnk - 1, a, b);
	// dbg(a); dbg(b); dbg(c);
	T *nw = new T(b -> sum);
	del_T(b); b = nw;
	root = merge(merge(a, b), c);
	// dbg(root);
}

void add(int k) {
	// cerr << "add " << k << endl;
	T *a, *b, *c;
	int rnk = find(root, x[k][use[k]] + inf);
	split(root, rnk, b, c);
	split(b, rnk - 1, a, b);
	// dbg(a); dbg(b); dbg(c);
	T *d = new T(x[k][use[k]] + inf - (a ? a -> sum : 0));
	T *e = new T((a ? a -> sum : 0) + b -> sum - x[k][use[k]] - inf);
	T *nw = merge(d, e);
	del_T(b); b = nw;
	root = merge(merge(a, b), c);
	// dbg(root);
}

void ch(int k) {
	del(k);
	use[k] ^= 1;
	add(k);
	cur = root -> mn;
}

signed main() {
	// freopen("in", "r", stdin);
	ios :: sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	cin >> n;
	for (int i = 0; i < n; ++ i)
		cin >> x[i][0] >> x[i][1];
	for (int i = 0; i < n; ++ i)
		use[i] = rand() % 2;
	multiset <int> st;
	st.insert(-inf); st.insert(inf);
	for (int i = 0; i < n; ++ i)
		st.insert(x[i][use[i]]);
	for (set <int> :: iterator it = st.begin(), oit; it != st.end(); ++ it) {
		if (it != st.begin()) root = merge(root, new T(*it - *oit));
		oit = it;
	}
	// dbg(root);
	cur = root -> mn;
	int mx = 0;
	double T = 1e3;
	while (T >= 1e-35) {
		// cerr << T << endl;
		int k = rand() % n;
		int old = cur;
		ch(k);
		int delta = cur - old;
		if (delta < 0 && exp(delta / T) * RAND_MAX <= rand()) ch(k);
		T *= 1.0 - 3e-5; mx = max(mx, cur);
		// dbg(root);
	}
	// dbg(root);
	cout << mx << endl;
	return 0;
}