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 Java8 (OpenJDK 1.8.0) (judge verdict: Time Limit Exceeded)

import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;
import java.io.BufferedReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		FastScanner in = new FastScanner(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskF solver = new TaskF();
		solver.solve(1, in, out);
		out.close();
	}

	static class TaskF {
		public void solve(int testNumber, FastScanner in, PrintWriter out) {
			// n <= 10^4, TL 5 sec.
			int n = in.nextInt();
			int[] x = new int[n];
			int[] y = new int[n];
			int min = Integer.MAX_VALUE;
			int max = Integer.MIN_VALUE;
			for (int i = 0; i < n; i++) {
				x[i] = in.nextInt();
				y[i] = in.nextInt();
				min = Math.min(min, x[i]);
				min = Math.min(min, y[i]);
				max = Math.max(max, x[i]);
				max = Math.max(max, y[i]);
			}
			int l = 0;
			int r = max - min + 1;
			while (r - l > 1) {
				int m = l + (r - l) / 2;
				if (can(n, x, y, m)) {
					l = m;
				} else {
					r = m;
				}
			}
			out.println(l);
		}

		private boolean can(int n, int[] x, int[] y, int d) {
			List<Clause> clauses = new ArrayList<>();
			boolean[][] f = new boolean[2][2];
			for (int i = 0; i < n; i++) {
				for (int j = i + 1; j < n; j++) {
					if (Math.abs(x[i] - x[j]) < d) {
						clauses.add(new Clause(i, j, true, false));
						clauses.add(new Clause(j, i, true, false));
					}
					if (Math.abs(x[i] - y[j]) < d) {
						clauses.add(new Clause(i, j, true, true));
						clauses.add(new Clause(j, i, false, false));
					}
					if (Math.abs(y[i] - y[j]) < d) {
						clauses.add(new Clause(i, j, false, true));
						clauses.add(new Clause(j, i, false, true));
					}
					if (Math.abs(y[i] - x[j]) < d) {
						clauses.add(new Clause(i, j, false, false));
						clauses.add(new Clause(j, i, true, true));
					}
				}
			}
			return new SAT2Solver(n).solve(clauses);
		}

		class Clause {
			int v1;
			int v2;
			boolean neg1;
			boolean neg2;

			Clause(int v1, int v2, boolean pos1, boolean pos2) {
				this.v1 = v1;
				this.v2 = v2;
				this.neg1 = !pos1;
				this.neg2 = !pos2;
			}

		}

		class SAT2Solver {
			List<Integer>[] g;
			boolean[] isTrue;
			int n;
			int numComps;
			int[] low;
			int[] vis;
			int[] comp;
			boolean[] onStack;
			int[] stack;
			int sp;
			int globalTime;

			SAT2Solver(int n) {
				this.n = n;
				isTrue = new boolean[2 * n];
				vis = new int[2 * n];
				low = new int[2 * n];
				stack = new int[2 * n];
				comp = new int[2 * n];
				onStack = new boolean[2 * n];
				g = new List[2 * n];
			}

			public boolean solve(List<Clause> clauses) {
				for (int i = 0; i < 2 * n; i++) {
					g[i] = new ArrayList<Integer>();
				}
				for (Clause clause : clauses) {
					int v1 = clause.v1;
					int v2 = clause.v2;
					if (clause.neg1) {
						v1 = negate(v1);
					}
					if (clause.neg2) {
						v2 = negate(v2);
					}
					//g[negate(v1)].add(v2);
					//g[negate(v2)].add(v1);
					g[v1].add(v2);
				}
				Arrays.fill(vis, -1);
				Arrays.fill(onStack, false);
				sp = 0;
				globalTime = 0;
				numComps = 0;
				for (int i = 0; i < 2 * n; i++) {
					if (vis[i] < 0) {
						dfsTarjan(i);
					}
				}
				int[] firstInComp = new int[numComps];
				Arrays.fill(firstInComp, -1);
				int[] nextSameComp = new int[2 * n];
				for (int i = 0; i < 2 * n; i++) {
					int c = comp[i];
					nextSameComp[i] = firstInComp[c];
					firstInComp[c] = i;
				}
				List<Integer>[] invertedCompEdges = new List[numComps];
				for (int i = 0; i < numComps; i++) {
					invertedCompEdges[i] = new ArrayList<Integer>();
				}
				for (int i = 0; i < 2 * n; i++) {
					for (int j : g[i]) {
						invertedCompEdges[comp[j]].add(comp[i]);
					}
				}
				boolean[] compIsTrue = new boolean[numComps];
				Arrays.fill(compIsTrue, true);
				for (int c = 0; c < numComps; c++) {
					if (!compIsTrue[c]) {
						continue;
					}
					for (int i = firstInComp[c]; i >= 0; i = nextSameComp[i]) {
						int nc = comp[negate(i)];
						if (c == nc) {
							return false;
						}
					}
					for (int i = firstInComp[c]; i >= 0; i = nextSameComp[i]) {
						int nc = comp[negate(i)];
						dfsReject(nc, invertedCompEdges, compIsTrue);
					}
				}
				for (int i = 0; i < 2 * n; i++) {
					isTrue[i] = compIsTrue[comp[i]];
				}
				for (int i = 0; i < n; i++) {
					if (isTrue[i] && isTrue[negate(i)]) {
						throw new AssertionError();
					}
					if (!isTrue[i] && !isTrue[negate(i)]) {
						return false;
					}
				}
				return true;
			}

			private int negate(int i) {
				return i + (i < n ? n : -n);
			}

			private void dfsReject(int c, List<Integer>[] invertedCompEdges, boolean[] compIsTrue) {
				if (!compIsTrue[c]) {
					return;
				}
				compIsTrue[c] = false;
				for (int p : invertedCompEdges[c]) {
					dfsReject(p, invertedCompEdges, compIsTrue);
				}
			}

			void dfsTarjan(int v) {
				vis[v] = globalTime;
				low[v] = globalTime;
				++globalTime;
				stack[sp++] = v;
				onStack[v] = true;
				for (int u : g[v]) {
					if (vis[u] < 0) {
						dfsTarjan(u);
						if (low[v] > low[u]) {
							low[v] = low[u];
						}
					} else if (onStack[u] && low[v] > vis[u]) {
						low[v] = vis[u];
					}
				}
				if (low[v] == vis[v]) {
					while (true) {
						int u = stack[--sp];
						onStack[u] = false;
						comp[u] = numComps;
						if (u == v) {
							break;
						}
					}
					++numComps;
				}
			}

		}

	}

	static class FastScanner {
		private BufferedReader in;
		private StringTokenizer st;

		public FastScanner(InputStream stream) {
			in = new BufferedReader(new InputStreamReader(stream));
		}

		public String next() {
			while (st == null || !st.hasMoreTokens()) {
				try {
					String rl = in.readLine();
					if (rl == null) {
						return null;
					}
					st = new StringTokenizer(rl);
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return st.nextToken();
		}

		public int nextInt() {
			return Integer.parseInt(next());
		}

	}
}