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>
//ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef pair<int,int> pii;
typedef pair<pii,int> ppii;
typedef pair<int,pii> pipi;
typedef pair<ll,ll> pll;
typedef pair<pll,ll> ppll;
typedef pair<ll,pll> plpl;
typedef tuple<ll,ll,ll> tl;
ll mod=1000000007;
ll mod2=998244353;
ll mod3=1000003;
ll mod4=998244853;
ll inf=1000000000000000000;
long double pi=3.14159265358979323846L;
#define rep(i,m,n) for(int i=m;i<n;i++)
#define rrep(i,n,m) for(int i=n;i>=m;i--)
int dh[4]={1,-1,0,0};
int dw[4]={0,0,1,-1};
int ddh[8]={-1,-1,-1,0,0,1,1,1};
int ddw[8]={-1,0,1,-1,1,-1,0,1};
ll lmax(ll a,ll b){
    if(a<b)return b;
    else return a;
}
ll lmin(ll a,ll b){
    if(a<b)return a;
    else return b;
}
ll gcd(ll a,ll b){
    if(a<b)swap(a,b);
    if(b==0)return a;
    if(a%b==0)return b;
    return gcd(b,a%b);
}
ll Pow(ll n,ll k){
    ll ret=1;
    ll now=n;
    while(k>0){
        if(k&1)ret*=now;
        now*=now;
        k/=2;
    }
    return ret;
}
ll gya[1000010];
ll kai[1000010];
ll beki(ll n,ll k,ll md){
  ll ret=1;
  ll now=n;
  while(k>0){
    if(k%2==1){
      ret*=now;
      ret%=md;
    }
    now*=now;
    now%=md;
    k/=2;
  }
  return ret;
}
ll gyaku(ll n,ll md){
  return beki(n,md-2,md);
}
int V;
vector<int> g[200010],rg[200010],vs;
bool used[200010];
int cmp[200010];
void add(int from,int to){
    g[from].push_back(to);
    rg[to].push_back(from);
}
void dfs(int now){
    used[now]=true;
    rep(i,0,g[now].size()){
        int ne=g[now][i];
        if(used[ne]==false)dfs(ne);
    }
    vs.push_back(now);
}
void rdfs(int now,int k){
    used[now]=true;
    cmp[now]=k;
    rep(i,0,rg[now].size()){
        int ne=rg[now][i];
        if(used[ne]==false)rdfs(ne,k);
    }
    
}
void scc(){
    fill(used,used+V,false);
    vs.clear();
    rep(i,0,V){
        if(used[i]==false)dfs((int)i);
    }
    fill(used,used+V,false);
    int k=0;
    rrep(i,vs.size()-1,0){
        int ne=vs[i];
        if(used[ne]==false)rdfs(ne,k);
        k++;
    }
}
int main(){
    ios::sync_with_stdio(false);cin.tie(0);
    int n;cin>>n;
    V=2*n;
    int x[n],y[n];
    rep(i,0,n)cin>>x[i]>>y[i];
    int u=1000000000,d=0;
    while(u-d>1){
        int mid=(u+d)/2;
        rep(i,0,V){
            g[i].clear();
            rg[i].clear();
        }
        fill(cmp,cmp+V,-1);
      int eee=0;
        rep(i,0,n-1){
            rep(j,i+1,n){
              int ee=0;
                if(abs(x[i]-x[j])>=mid){
                    ee=1;
                }
                else{
                    add(i,j+n);
                    add(j,i+n);
                }
                if(abs(x[i]-y[j])>=mid){
                    ee=1;
                }
                else{
                    add(i,j);
                    add(j+n,i+n);
                }
                if(abs(y[i]-x[j])>=mid){
                    ee=1;
                }
                else{
                    add(i+n,j+n);
                    add(j,i);
                }
                if(abs(y[i]-y[j])>=mid){
                    ee=1;
                }
                else{
                    add(i+n,j);
                    add(j+n,i);
                }
              if(ee==0){
                eee=1;
                break;
              }
            }
              if(eee==1)break;
        }
      if(eee){
        u=mid;
        continue;
      }
        scc();
        int r=0;
        
        rep(i,0,n){
            if(cmp[i]==cmp[i+n]){
                r=1;
                break;
            }
        }
        if(r==1)u=mid;
        else d=mid;
    }
    cout<<d<<endl;
}