#include using namespace std; using ll = long long; #define rep(i, s, t) for (int i = (int)(s); i < (int)(t); ++i) #define revrep(i, t, s) for (int i = (int)(t)-1; i >= (int)(s); --i) #define all(x) begin(x), end(x) template bool chmax(T& a, const T& b) { return a < b ? (a = b, 1) : 0; } template bool chmin(T& a, const T& b) { return a > b ? (a = b, 1) : 0; } template class RangeTree { public: RangeTree() = default; explicit RangeTree(const std::vector>& pts) { for (auto& [x, y, v] : pts) xs.push_back(x); std::sort(xs.begin(), xs.end()); xs.erase(std::unique(xs.begin(), xs.end()), xs.end()); int n = xs.size(); size = 1; while (size < n) size <<= 1; node.resize(2 * size); sum.resize(2 * size); for (auto& [x, y, v] : pts) { int i = std::lower_bound(xs.begin(), xs.end(), x) - xs.begin(); node[size + i].emplace_back(y, v); } for (int i = 0; i < n; ++i) { std::sort(node[size + i].begin(), node[size + i].end()); } for (int i = size - 1; i > 0; --i) { std::merge(node[2 * i].begin(), node[2 * i].end(), node[2 * i + 1].begin(), node[2 * i + 1].end(), std::back_inserter(node[i])); } for (int i = 0; i < size + n; ++i) { sum[i].resize(node[i].size() + 1); for (int j = 0; j < (int)node[i].size(); ++j) { sum[i][j + 1] = sum[i][j] + node[i][j].second; } } } T fold(X sx, X tx, Y sy, Y ty) const { int l = std::lower_bound(xs.begin(), xs.end(), sx) - xs.begin(); int r = std::lower_bound(xs.begin(), xs.end(), tx) - xs.begin(); T ret = 0; auto cmp = [&](const std::pair& p, Y y) { return p.first < y; }; for (l += size, r += size; l < r; l >>= 1, r >>= 1) { if (l & 1) { int hi = std::lower_bound(node[l].begin(), node[l].end(), ty, cmp) - node[l].begin(); int lo = std::lower_bound(node[l].begin(), node[l].end(), sy, cmp) - node[l].begin(); ret += sum[l][hi] - sum[l][lo]; ++l; } if (r & 1) { --r; int hi = std::lower_bound(node[r].begin(), node[r].end(), ty, cmp) - node[r].begin(); int lo = std::lower_bound(node[r].begin(), node[r].end(), sy, cmp) - node[r].begin(); ret += sum[r][hi] - sum[r][lo]; } } return ret; } private: int size; std::vector xs; std::vector>> node; std::vector> sum; }; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout << fixed << setprecision(15); int N; cin >> N; vector> pts; rep(i, 0, N) { int x, y; cin >> x >> y; pts.push_back({x + y, x - y, 1}); } RangeTree rt(pts); int ans = 1e9; for (auto [x, y, _] : pts) { int d1, d2; { int lb = 0, ub = 1e7; while (ub - lb > 1) { int m = (lb + ub) / 2; if (rt.fold(x - m, x + m + 1, y - m, y + m + 1) == N) { ub = m; } else { lb = m; } } d2 = ub; } { int lb = 0, ub = 1e7; while (ub - lb > 1) { int m = (lb + ub) / 2; if (rt.fold(x - m, x + m + 1, y - m, y + m + 1) == 1) { lb = m; } else { ub = m; } } d1 = ub; } chmin(ans, d2 - d1); } cout << ans << endl; }