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>
#define reg register
#define inf 1000000007
#define maxn 2000001
using namespace std;
struct node{int x, id;} a[maxn]; 
int n, x[maxn], y[maxn], d[maxn], go[maxn], cntx;
int num[maxn], dfn[maxn], low[maxn], vis[maxn];
int cnt, id[maxn], g[maxn], ans, fi[maxn], nt[maxn];
int  c[maxn], st[maxn], top, top1, tag[maxn];
inline int  read() {
    reg int s = 0, t = 0; reg char ch = getchar();
    while(ch > '9' || ch < '0') t |= ch == '-', ch = getchar();
    while(ch >= '0' && ch <= '9') s = (s << 1) + (s << 3) + (ch ^ 48), ch = getchar();
    return t ? -s : s;
}
bool cmp(node g, node h){return g.x < h.x;}
void add(int u, int v){
    nt[++cntx] = fi[u]; fi[u] = cntx; go[cntx] = v;
}
void build(int k, int l, int r){
    if(l == r) {num[l] = k; return; } 
    int mid = l + r >> 1;
    build(k << 1, l, mid); 
    build(k << 1 | 1, mid + 1, r);
    d[++cnt] = k; g[cnt] = k << 1;
    d[++cnt] = k; g[cnt] = k << 1 | 1;
}
void insert(int now, int k, int l, int r, int L, int R){
    if(l > r) return;
    if(L <= l && r <= R){
        d[++cnt] = now; g[cnt] = k; return;
    }
    int mid = l + r >> 1;
    if(L <= mid) insert(now, k << 1, l, mid, L, R);
    if(R > mid) insert(now, k << 1 | 1, mid + 1, r, L, R); 
}
void tarjan(int x){
    dfn[x] = low[x] = ++top; 
    st[++top1] = x; vis[x] = 1;
    for(int i = fi[x]; i; i = nt[i]){
        int v = go[i]; 
        if(!dfn[v]) tarjan(v);
        if(vis[v]) low[x] = min(low[x], low[v]);
    }
    if(low[x] == dfn[x]){
        while(int y = st[top1--]){
            tag[y] = x; vis[y] = 0;
            if(x == y) break;
        }
    }
}
bool solve(int x){
    cntx = 0;
    for(int i = 1; i <= 200000; i++) tag[i] = i, dfn[i] = 0, fi[i] = 0;
    top = 0; top1 = 0;  cnt = 0; 
    build(1, 1, n << 1); 
    for(int i = 1; i <= n; i++){
        int o = (i & 1) ? 1 : -1;
        d[++cnt] = num[id[i]]; g[cnt] = num[id[i + o] + n];
        d[++cnt] = num[id[i + o] + n]; g[cnt] = num[id[i]];
        int R = lower_bound(c + 1, c + n + 1, c[id[i]] + x) - c - 1;
        int L = upper_bound(c + 1, c + n + 1, c[id[i]] - x) - c;
        insert(num[id[i]], 1, 1, n << 1, L + n, id[i] + n - 1);
        insert(num[id[i]], 1, 1, n << 1, id[i] + n + 1, R + n); 
    }
    for(int i = 1; i <= cnt; i++) add(d[i], g[i]);
    tarjan(1);
    for(int i = 1; i <= n; i++)
    for(int i = 1; i <= n; i++){
        if(tag[num[id[i]]] == tag[num[id[i] + n]]) return false;
    }
    return true;
}
int main(){
    n = read(); 
    for(int i = 1; i <= n; i++) {
        int x = read(), y = read();
        a[i * 2 - 1].x = x; a[i * 2 - 1].id = i * 2 - 1;
        a[i * 2].x = y; a[i * 2].id = i * 2;
    }
    sort(a + 1, a + n + n + 1, cmp);
    for(int i = 1; i <= n << 1; i++) c[i] = a[i].x;
    for(int i = 1; i <= n << 1; i++) id[a[i].id] = i;
    int l = 0, r = inf; n <<= 1; ans = 0;
    while(l <= r){
        int mid = l + r >> 1;
        if(solve(mid)) ans = mid, l = mid + 1;
        else r = mid - 1;
    }
    printf("%d\n", ans);
}