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)

// ===================================
//   author: M_sea
//   website: http://m-sea-blog.com/
// ===================================
#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <cmath>
#define re register
#define mp make_pair
#define clear(x,y) memset(x,y,sizeof(x))
using namespace std;

inline int read() {
    int X=0,w=1; char c=getchar();
    while (c<'0'||c>'9') { if (c=='-') w=-1; c=getchar(); }
    while (c>='0'&&c<='9') X=X*10+c-'0',c=getchar();
    return X*w;
}

const int N=200000+10;

int n,x[2][N];
pair<int,int> a[N];

struct edge { int v,nxt; } e[N*10];
int head[N],ecnt=0;
inline void addEdge(int u,int v) {
    e[++ecnt]=(edge){v,head[u]},head[u]=ecnt;
}

#define ls (o<<1)
#define rs (o<<1|1)
int ncnt,id[N];
inline void build(int o,int l,int r) {
    if (l==r) { id[o]=a[l].second; return; }
    id[o]=++ncnt; int mid=(l+r)>>1;
    build(ls,l,mid),build(rs,mid+1,r);
    addEdge(id[o],id[ls]),addEdge(id[o],id[rs]);
}
inline void link(int o,int l,int r,int ql,int qr,int u) {
    if (ql>qr) return;
    if (ql<=l&&r<=qr) { addEdge(u,id[o]); return; }
    int mid=(l+r)>>1;
    if (ql<=mid) link(ls,l,mid,ql,qr,u);
    if (qr>mid) link(rs,mid+1,r,ql,qr,u);
}
#undef ls
#undef rs

int dfn[N],low[N],tim=0,bl[N],scc=0,sta[N],in[N],top=0;
inline void tarjan(int u) {
    dfn[u]=low[u]=++tim,sta[++top]=u,in[u]=1;
    for (re int i=head[u];i;i=e[i].nxt) {
        int v=e[i].v;
        if (!dfn[v]) tarjan(v),low[u]=min(low[u],low[v]);
        else if (in[v]) low[u]=min(low[u],dfn[v]);
    }
    if (dfn[u]==low[u]) { ++scc;
        while (233) {
            int t=sta[top--]; bl[t]=scc,in[t]=0;
            if (t==u) break;
        }
    }
}

inline int check(int mid) {
    clear(head,0),ecnt=0;
    clear(dfn,0),clear(low,0),clear(bl,0),clear(in,0),tim=scc=top=0;
    ncnt=n<<1,build(1,1,n<<1);
    for (re int i=1;i<=n;++i)
        for (re int j=0;j<2;++j) {
            int l=lower_bound(a+1,a+n+n+1,mp(x[j][i]-mid+1,0))-a;
            int r=upper_bound(a+1,a+n+n+1,mp(x[j][i]+mid-1,n<<1|1))-a-1;
            int m=lower_bound(a+1,a+n+n+1,mp(x[j][i],i+(j^1)*n))-a;
            link(1,1,n<<1,l,m-1,i+j*n),link(1,1,n<<1,m+1,r,i+j*n);
        }
    for (re int i=1;i<=ncnt;++i) if (!dfn[i]) tarjan(i);
    for (re int i=1;i<=n;++i) if (bl[i]==bl[i+n]) return 0;
    return 1;
}

int main() {
    n=read();
    for (re int i=1;i<=n;++i) {
        x[0][i]=read(),x[1][i]=read();
        a[i]=mp(x[0][i],i+n),a[i+n]=mp(x[1][i],i);
    }
    sort(a+1,a+n+n+1);
    int L=0,R=1e9;
    while (L<R) {
        int mid=(L+R+1)>>1;
        if (check(mid)) L=mid;
        else R=mid-1;
    }
    printf("%d\n",L);
    return 0;
}
//qwq