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 OUT(x) cout << #x << " = " << x << endl
#define rep(i, n)             for (int (i) = 0; (i) < (int)(n); (i)++)
#define rer(i, l, r)          for (int (i) = (int)(l); (i) <= (int)(r); (i)++)
#define reu(i, l, r)          for (int (i) = (int)(l); (i) < (int)(r); (i)++)
#define all(x)                (x).begin(), (x).end()
#define rall(x)               (x).rbegin(), (x).rend()
template<typename T> void pv(T a, T b) { for (T i = a; i != b; i ++) cout << *i << " "; cout << endl; }
template<typename T, typename U> inline void amin(T &x, U y) { if (y < x) x = y; }
template<typename T, typename U> inline void amax(T &x, U y) { if (x < y) x = y; }
int in() { int x; scanf("%d", &x); return x; }
long long lin() { long long x; scanf("%lld", &x); return x; }

int V;
vector<int> g[20202];
vector<int> rg[20202];
vector<int> order;
bool used[20202];
int cmp[20202];

int n;
vector<int> x, y;

void add_edge(int from, int to) {
        g[from].push_back(to);
        rg[to].push_back(from);
}
void dfs(int v) {
        used[v] = true;
        for (auto i : g[v]) if (!used[i]) dfs(i);
        order.push_back(v);
}
void rdfs(int v, int k) {
        used[v] = true;
        cmp[v] = k;
        for (auto i : rg[v]) if (!used[i]) rdfs(i, k);
}
int StronglyConnectedComponent() {
        memset(used, 0, sizeof(used));
        order.clear();
        for (int i = 0; i < V; i ++) if (!used[i]) dfs(i);
        memset(used, 0, sizeof(used));
        int k = 0;
        for (int i = order.size() - 1; i >= 0; i --) if (!used[order[i]]) rdfs(order[i], k ++);
        return k;
}

bool B(int d) {
        rep(i, 20202) g[i].clear();
        rep(i, 20202) rg[i].clear();
        order.clear();
        rep(i, 20202) used[i] = 0;
        rep(i, 20202) cmp[i] = 0;

        int d1, d2, d3, d4;
        rep(i, n) reu(j, i + 1, n) {
                d1 = abs(x[i] - x[j]);
                d2 = abs(x[i] - y[j]);
                d3 = abs(y[i] - x[j]);
                d4 = abs(y[i] - y[j]);
                //OUT(d1);
                //OUT(d2);
                //OUT(d3);
                //OUT(d4);
                if (d1 >= d && d2 >= d && d3 >= d && d4 >= d) continue;
                else if (d1 < d && d2 < d && d3 < d && d4 < d) return false;
                else if (d1 >= d && d2 < d && d3 < d && d4 < d) {
                        add_edge(i + n, i);
                        add_edge(j + n, j);
                }
                else if (d1 < d && d2 >= d && d3 < d && d4 < d) {
                        add_edge(i + n, i);
                        add_edge(j, j + n);
                }
                else if (d1 < d && d2 < d && d3 >= d && d4 < d) {
                        add_edge(i, i + n);
                        add_edge(j + n, j);
                }
                else if (d1 < d && d2 < d && d3 < d && d4 >= d) {
                        add_edge(i, i + n);
                        add_edge(j, j + n);
                }
                else if (d1 >= d && d2 >= d && d3 < d && d4 < d) {
                        add_edge(i + n, i);
                }
                else if (d1 >= d && d2 < d && d3 >= d && d4 < d) {
                        add_edge(j + n, j);
                }
                else if (d1 >= d && d2 < d && d3 < d && d4 >= d) {
                        add_edge(i, j);
                        add_edge(i + n, j + n);
                        add_edge(j, i);
                        add_edge(j + n, i + n);
                }
                else if (d1 < d && d2 >= d && d3 >= d && d4 < d) {
                        add_edge(i, j + n);
                        add_edge(i + n, j);
                        add_edge(j + n, i);
                        add_edge(j, i + n);
                }
                else if (d1 < d && d2 >= d && d3 < d && d4 >= d) {
                        add_edge(j, j + n);
                }
                else if (d1 < d && d2 < d && d3 >= d && d4 >= d) {
                        add_edge(i, i + n);
                }
                else if (d1 >= d && d2 >= d && d3 >= d && d4 < d) {
                        add_edge(i + n, j);
                        add_edge(j + n, i);
                }
                else if (d1 >= d && d2 >= d && d3 < d && d4 >= d) {
                        add_edge(i + n, j + n);
                        add_edge(j, i);
                }
                else if (d1 >= d && d2 < d && d3 >= d && d4 >= d) {
                        add_edge(i, j);
                        add_edge(j + n, i + n);
                }
                else if (d1 < d && d2 >= d && d3 >= d && d4 >= d) {
                        add_edge(i, j + n);
                        add_edge(j, i + n);
                }
        }
        StronglyConnectedComponent();
        rep(i, n) if (cmp[i] == cmp[i + n]) return false;
        return true;
}

static const int INF = 0x3f3f3f3f;

signed main() { 
        cin >> n;
        V = 2 * n;
        x.resize(n), y.resize(n);
        rep(i, n) cin >> x[i] >> y[i];
        int l = 0, r = INF;
        while (r - l > 1) {
                int mid = (l + r) / 2;
                //OUT(r);
                //OUT(l);
                //OUT(mid);
                if (B(mid)) l = mid;
                else r = mid;
        }
        cout << l << endl;
        return 0;
}