#include namespace { #pragma GCC diagnostic ignored "-Wunused-function" #include #pragma GCC diagnostic warning "-Wunused-function" using namespace std; using namespace atcoder; #define rep(i,n) for(int i = 0; i < (int)(n); i++) #define rrep(i,n) for(int i = (int)(n) - 1; i >= 0; i--) #define all(x) begin(x), end(x) #define rall(x) rbegin(x), rend(x) template bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; } template bool chmin(T& a, const T& b) { if (b < a) { a = b; return true; } else return false; } using ll = long long; using P = pair; using VI = vector; using VVI = vector; using VL = vector; using VVL = vector; template vector manhattan_dist_max(const vector>& ps) { T v1, v2, v3, v4; v1 = v3 = numeric_limits::max(); v2 = v4 = numeric_limits::min(); for(auto [x, y] : ps) { T s = x + y; T t = -x + y; chmin(v1, s); chmax(v2, s); chmin(v3, t); chmax(v4, t); } vector res(ps.size()); int i = 0; for(auto [x, y] : ps) { T s = x + y; T t = -x + y; res[i++] = max({s - v1, v2 - s, t - v3, v4 - t}); } return res; } template struct BIT { vector d; int n; template BIT(auto&&... args) : d(forward(args)...), n(d.size()) { if constexpr (dual) reverse(d.begin(), d.end()); for (int i = 1; i < n; i++) { int j = i + (i & -i); if (j < n) d[j] = op(d[j], d[i]); } } BIT(int n) : d(n, e()), n(n) {} void apply(int i, S x) { if constexpr (cursor_indexing) { assert(0 <= i && i <= n); if constexpr (dual) i = n - i; } else { assert(0 <= i && i < n); if constexpr (dual) i = n - 1 - i; } if (i == 0) { if (n > 0) d[i] = op(d[i], x); } else { while (i < n) { d[i] = op(d[i], x); i += i & -i; } } } S sum(int i) { if constexpr (cursor_indexing) { assert(0 <= i && i <= n); if constexpr (dual) i = n - i; if (i == 0) return e(); i--; } else { assert(0 <= i && i < n); if constexpr (dual) i = n - 1 - i; } S res = d[i]; while (i) { i -= i & -i; res = op(res, d[i]); } return res; } }; template vector manhattan_dist_min(const vector>& points) { const int n = points.size(); assert(n >= 2); struct S { pair p; int i; }; vector ps(n); for (int i = 0; i < n; i++) ps[i] = {points[i], i}; sort(ps.begin(), ps.end(), [](const S& p1, const S& p2) { return p1.p.first < p2.p.first; }); vector vals(n); for (int i = 0; i < n; i++) vals[i] = ps[i].p.second; sort(vals.begin(), vals.end()); vals.erase(unique(vals.begin(), vals.end()), vals.end()); const int sz = vals.size(); constexpr T inf_min = numeric_limits::min() / 2; constexpr T inf_max = numeric_limits::max() / 2; vector ans(n, inf_max); vector y_id(n); auto e = []{ return inf_min; }; auto op = [](T x, T y) { return max(x, y); }; BIT bt1(sz); BIT bt2(sz); for (int i = 0; i < n; i++) { auto [x, y] = ps[i].p; y_id[i] = lower_bound(vals.begin(), vals.end(), y) - vals.begin(); chmin(ans[ps[i].i], min( x + y - bt1.sum(y_id[i]), x - y - bt2.sum(y_id[i]) )); bt1.apply(y_id[i], x + y); bt2.apply(y_id[i], x - y); } bt1.d.assign(sz, e()); bt2.d.assign(sz, e()); for (int i = n - 1; i >= 0; i--) { auto [x, y] = ps[i].p; chmin(ans[ps[i].i], min( -bt2.sum(y_id[i]) - (x + y), -bt1.sum(y_id[i]) - (x - y) )); bt2.apply(y_id[i], -(x + y)); bt1.apply(y_id[i], -(x - y)); } return ans; } } int main() { ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; vector> xy(n); for(auto& [x, y] : xy) cin >> x >> y; VI mx = manhattan_dist_max(xy); VI mn = manhattan_dist_min(xy); int ans = 2001001001; rep(i, n) chmin(ans, mx[i] - mn[i]); cout << ans << '\n'; }