#include #include using namespace std; using namespace atcoder; const int INF = 1E9; int min_op(int u, int v) { return min(u, v); } int min_e() { return INF; } int max_op(int u, int v) { return max(u, v); } int max_e() { return -INF; } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); int n; cin >> n; vector x(n), y(n); for (int i = 0; i < n; i++) { cin >> x[i] >> y[i]; } vector mx(n, -INF), mi(n, INF); auto solve = [&]() { vector p(n), prc(n); iota(p.begin(), p.end(), 0); iota(prc.begin(), prc.end(), 0); sort(p.begin(), p.end(), [&](int u, int v) { return tuple(x[u], y[u], u) < tuple(x[v], y[v], v); }); sort(prc.begin(), prc.end(), [&](int u, int v) { return tuple(y[u], u) < tuple(y[v], v); }); vector pos(n); for (int i = 0; i < n; i++) { pos[p[i]] = i; } segtree mis(n); segtree mas(n); for (int v : prc) { int sum = x[v] + y[v]; mi[v] = min(mi[v], sum - mas.prod(0, pos[v])); mx[v] = max(mx[v], sum - mis.prod(0, pos[v])); mas.set(pos[v], sum); mis.set(pos[v], sum); } }; for (int sx = 0; sx < 2; sx++) { for (int sy = 0; sy < 2; sy++) { solve(); transform(y.begin(), y.end(), y.begin(), [](int u) { return -u; }); } transform(x.begin(), x.end(), x.begin(), [](int u) { return -u; }); } int ans = INF; for (int i = 0; i < n; i++) { cerr << mx[i] << " " << mi[i] << '\n'; ans = min(ans, mx[i] - mi[i]); } cout << ans; }