/** * date : 2026-10-09 23:43:14 * author : yamadanull */ // ===== BEGIN INCLUDE: ../../template/template.hpp ===== #include using namespace std; // ===== BEGIN INCLUDE: util.hpp ===== namespace yamada { using ll = long long; using i32 = int; using u32 = unsigned int; using i64 = long long; using u64 = unsigned long long; using i128 = __int128_t; using u128 = __uint128_t; using lld = long double; template using vc = vector; template using vvc = vector>; template using vvvc = vector>>; template using vvvvc = vector>>>; using vint = vector; using vl = vector; using vd = vector; using vs = vector; using vvl = vector>; using vvvl = vector>>; using vvvvl = vector>>>; template using minpq = priority_queue, greater>; template using maxpq = priority_queue, less>; template struct pr : pair { template pr(Args... args) : pair(args...) {} using pair::first; using pair::second; pr &operator+=(const pr &r) { first += r.first; second += r.second; return *this; } pr &operator-=(const pr &r) { first -= r.first; second -= r.second; return *this; } pr &operator*=(const pr &r) { first *= r.first; second *= r.second; return *this; } template pr &operator*=(const S &r) { first *= r, second *= r; return *this; } pr operator+(const pr &r) const { return pr(*this) += r; } pr operator-(const pr &r) const { return pr(*this) -= r; } pr operator*(const pr &r) const { return pr(*this) *= r; } template pr operator*(const S &r) const { return pr(*this) *= r; } pr operator-() const { return pr{-first, -second}; } }; using pint = pr; using pl = pr; using vp = vc; using vvp = vvc; template int len(const T &t) { return t.size(); } constexpr int inf = 1001001001; constexpr long long infLL = 4004004004004004004LL; template inline bool amin(T &x, U y) { return (y < x) ? (x = y, true) : false; } template inline bool amax(T &x, U y) { return (x < y) ? (x = y, true) : false; } template pair mkp(const T &t, const U &u) { return make_pair(t, u); } template tuple mkt(const Args&... args) { return make_tuple(args...); } template inline long long Sum(const vector &v) { return accumulate(v.begin(), v.end(), T(0)); } template int lb(const vector &v, const T &a) { return ranges::lower_bound(v, a) - v.begin(); } template int ub(const vector &v, const T &a) { return ranges::upper_bound(v, a) - v.begin(); } constexpr long long TEN(int n) { long long ret = 1, x = 10; for (; n; x *= x, n >>= 1) ret *= (n & 1 ? x : 1); return ret; } template vector mkrui(const vector &v, const bool rev = false) { vector ret(v.size() + 1); if (rev) { for (int i = (int)v.size() - 1; i >= 0; i--) ret[i] = v[i] + ret[i + 1]; } else { for (int i = 0; i < (int)v.size(); i++) ret[i + 1] = ret[i] + v[i]; } return ret; }; template vector mkuni(const vector &v) { vector ret(v); ranges::sort(ret); ret.erase(ranges::unique(ret).begin(), ret.end()); return ret; } template vector mkord(int N, const F &f) { vector ord = views::iota(0, N) | ranges::to(); ranges::sort(ord, f); return ord; } template vector mkinv(const vector &v) { vector inv(ranges::max(v) + 1, -1); for (int i = 0; i < (int)v.size(); i++) inv[v[i]] = i; return inv; } vector mkiota(int N) { return views::iota(0, N) | ranges::to(); } vector p_mrg(const vector &f, const vector &g) { // g o f return f | views::transform([&](auto a) { return g[a]; }) | ranges::to(); } template // f: old_idx -> new_idx vector p_shf(const vector& A, const vector& f, const bool inv = false) { int n = A.size(); vector ret(n); if (!inv) for (int i = 0; i < n; i++) ret[f[i]] = A[i]; else for (int i = 0; i < n; i++) ret[i] = A[f[i]]; return ret; } template T mkrev(const T &v) { return v | views::reverse | ranges::to(); } template bool nxp(C &v) { return ranges::next_permutation(v).found; } template void nxp(int N, F f) { auto a = views::iota(0, N) | ranges::to(); do { f(a); } while (nxp(a)); } // i 要素目 : [0, A[i]) template void Product(const vector &A, const F& f) { vector cur; auto dfs = [&](this auto dfs, int i) -> void { if (i == (int)A.size()) { f(cur); return; } for (int j = 0; j < A[i]; j++) cur.emplace_back(j), dfs(i + 1), cur.pop_back(); }; dfs(0); } // i 要素目 : [0, M) template void Product(const int N, const int M, const F& f) { vector A(N, M); Product(A, f); } template vector Digit(T a, const U &x, int siz = -1) { vector ret; while (a > 0) { ret.emplace_back(a % x); a /= x; } if (siz >= 0) ret.resize(siz); return ret; } // F : function(void(T&)), mod を取る操作 // T : 整数型のときはオーバーフローに注意する template T Power(T a, long long n, const T &I, const function &f) { T res = I; for (; n; f(a = a * a), n >>= 1) { if (n & 1) f(res = res * a); } return res; } // T : 整数型のときはオーバーフローに注意する template T Power(T a, long long n, const T &I = T{1}) { return Power(a, n, I, function{[](T &) -> void {}}); } template vector Transpose(const vector &A) { if (A.empty()) return {}; return views::iota(0, (int)A[0].size()) | views::transform([&](auto j) { return A | views::transform([&](auto&& a) { return a[j]; }) | ranges::to(); }) | ranges::to>(); } template vector RotateGrid(const vector &A) { if (A.empty()) return {}; return views::iota(0, (int)A[0].size()) | views::transform([&](auto j) { return A | views::transform([&](auto&& a) { return a[j]; }) | ranges::to(); }) | views::reverse | ranges::to>(); } template T bisect(T ok, T bad, F pred) { if (ok == bad) return ok; while (bad - ok > 1) { T mid = ok + (bad - ok) / 2; (pred(mid) ? ok : bad) = mid; } return bad; } template T bisect_double(T ok, T bad, F pred, int iter = 100) { if (ok == bad) return ok; while (iter--) { T mid = ok + (bad - ok) / 2; (pred(mid) ? ok : bad) = mid; } return bad; } template bool inLR(T0 L, T1 x, T2 R){ return L <= x && x < R; } bool YESNO(bool b) { cout << (b ? "YES\n" : "NO\n"); return b; } bool YesNo(bool b) { cout << (b ? "Yes\n" : "No\n"); return b; } bool yesno(bool b) { cout << (b ? "yes\n" : "no\n"); return b; } long long Isqrt(long long n) { if (n <= 0) return 0; long long x = sqrt(n); while ((x + 1) * (x + 1) <= n) x++; while (x * x > n) x--; return x; } template struct CumulativeSum { vector S; CumulativeSum(vector &A) : S(A.size() + 1) { for (int i = 0; i < (int)A.size(); i++) S[i + 1] = S[i] + A[i]; } T query(int l, int r) { return (l <= r ? S[r] - S[l] : T(0)); } T query() { return S.back(); } inline T operator()(int l, int r) { return query(l, r); } inline T operator()() { return query(); } }; // 速度よりオーバーフロー対策優先 template T Floor(T a, T b) { assert(b != 0); if (b < 0) a = -a, b = -b; return a / b - (a % b < 0); } template T Under(T a, T b) { assert(b != 0); if (b < 0) a = -a, b = -b; return a / b - (a % b <= 0); } template T Ceil (T a, T b) { assert(b != 0); if (b < 0) a = -a, b = -b; return a / b + (a % b > 0); } template T Over (T a, T b) { assert(b != 0); if (b < 0) a = -a, b = -b; return a / b + (a % b >= 0); } template T Modulo(T a, T b) { assert(b > 0); T c = a % b; return c < 0 ? c + b : c; } template pair DivMod(T a, T b) { assert(b > 0); T q = a / b, r = a % b; if (r < 0) --q, r += b; return {q, r}; } string rds() { string S; cin >> S; return S; } int rdi() { int x; cin >> x; return x; } char rdc() { char c; cin >> c; return c; } long long rdl() { long long x; cin >> x; return x; } template string tof(const mint &a) { for (int deno = 1; deno <= iter; deno++) { mint inv = ((mint)deno).inverse(); for (int nume = 0; nume <= iter; nume++) { mint val = inv * nume; if (val == a) { if (deno == 1) return to_string(nume); return to_string(nume) + "/" + to_string(deno); } else if (-val == a) { if (deno == 1) return to_string(-nume); return to_string(-nume) + "/" + to_string(deno); } } } return "!NF"; } } // namespace yamada // ===== END INCLUDE: util.hpp ===== // ===== BEGIN INCLUDE: bitop.hpp ===== namespace yamada { __attribute__((target("popcnt"))) inline int popcnt(const u64 &a) { return __builtin_popcountll(a); } inline int lsb(const u64 &a) { return a ? __builtin_ctzll(a) : 64; } inline int msb(const u64 &a) { return a ? 63 - __builtin_clzll(a) : -1; } template inline int gbit(const T &a, int i) { return (a >> i) & 1; } template inline void sbit(T &a, int i, bool b) { if (gbit(a, i) != b) a ^= T(1) << i; } constexpr long long PW(int n) { return 1LL << n; } constexpr long long MSK(int n) { return (1LL << n) - 1; } string tog(int msk, int N) { return views::iota(0, N) | views::transform([&](auto i) { return msk >> i & 1 ? '#' : '.'; }) | ranges::to(); } } // namespace yamada // ===== END INCLUDE: bitop.hpp ===== // ===== BEGIN INCLUDE: io.hpp ===== namespace yamada { istream &operator>>(istream &is, __int128_t &x) { string S; is >> S; x = 0; bool f{}; for (auto &c : S) { if (c == '-') { f = 1; continue; } x *= 10; x += c - '0'; } if (f) x = -x; return is; } istream &operator>>(istream &is, __uint128_t &x) { string S; is >> S; x = 0; for (auto &c : S) { x *= 10; x += c - '0'; } return is; } ostream &operator<<(ostream &os, __int128_t x) { if (x == 0) return os << 0; if (x < 0) os << '-', x = -x; string S; while (x) S.push_back('0' + x % 10), x /= 10; ranges::reverse(S); return os << S; } ostream &operator<<(ostream &os, __uint128_t x) { if (x == 0) return os << 0; string S; while (x) S.push_back('0' + x % 10), x /= 10; ranges::reverse(S); return os << S; } template // tuple / pair / array concept TupleLike = requires { tuple_size>::value; }; template // vector / set / ranges::view など(set は入力不可) concept ListLike = ranges::input_range && !convertible_to && !TupleLike; template ostream& operator<<(ostream&, const T&); template istream& operator>>(istream&, T&&); template ostream& operator<<(ostream&, const R&); template istream& operator>>(istream&, R&&); template ostream& operator<<(ostream& os, const T& t) { bool f{}; apply([&](const auto&... x) { (..., (os << (exchange(f, 1) ? " " : "") << x)); }, t); return os; } template istream& operator>>(istream& is, T&& t) { apply([&](auto&... x) { (..., (is >> x)); }, t); return is; } template ostream& operator<<(ostream& os, const R& a) { bool f{}; for (const auto& x : a) os << (exchange(f, 1) ? " " : "") << x; return os; } template istream& operator>>(istream& is, R&& a) { for (auto&& x : a) is >> x; return is; } template void IN(T&&... x) { (cin >> ... >> x); } template void OUT (const T&... x) { bool f{}; (..., (cout << (exchange(f, 1) ? " " : "") << x)); cout << '\n'; } template // "Flush after OUT" void FOUT(const T&... x) { bool f{}; (..., (cout << (exchange(f, 1) ? " " : "") << x)); cout << endl; } template // "WithOUT ln" void WOUT(const T&... x) { bool f{}; (..., (cout << (exchange(f, 1) ? " " : "") << x)); } struct IoSetupYamada { IoSetupYamada() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); cerr << fixed << setprecision(7); } } iosetupyamada; namespace DebugImpl { void dump(const char& t) { cerr << t; } void dump(const string& t) { cerr << t; } void dump(const bool& t) { cerr << (t ? "true" : "false"); } void dump(__int128_t t) { cerr << t; } void dump(__uint128_t t) { cerr << t; } template void dump(const T& t) { string res; if (t == yamada::inf) res = "inf"; if constexpr (is_signed::value) { if (t == -yamada::inf) res = "-inf"; } if constexpr (sizeof(T) == 8) { if (t == yamada::infLL) res = "inf"; if constexpr (is_signed::value) { if (t == -yamada::infLL) res = "-inf"; } } if (res.empty()) res = to_string(t); cerr << res; } template requires (!ListLike && !TupleLike && !integral) void dump(const T& t) { cerr << t; } template void dump(const R&); template void dump(const T&); template void dump(const R& a) { bool f{}; for (const auto& x : a) { cerr << (exchange(f, 1) ? ", " : "[ "); dump(x); } cerr << " ]"; } template void dump(const T& t) { bool f{}; apply([&](const auto&... x) { (..., (cerr << (exchange(f, 1) ? ", " : "( "), dump(x))); }, t); cerr << " )"; } template void trace(const T&... x) { bool f{}; (..., (cerr << (exchange(f, 1) ? ", " : " "), dump(x))); cerr << endl; } } // namespace DebugImpl } // namespace yamada #ifdef yamadaDebug #define ERR(...) \ do { \ std::cerr << "## " << #__VA_ARGS__ << " = "; \ yamada::DebugImpl::trace(__VA_ARGS__); \ } while (0) #else #define ERR(...) (void(0)) #endif // ===== END INCLUDE: io.hpp ===== // ===== BEGIN INCLUDE: ranges.hpp ===== namespace yamada { constexpr auto All = ranges::all_of; // of なし (Python に合わせている) constexpr auto Any = ranges::any_of; // 同上 constexpr auto BinarySearch = ranges::binary_search; constexpr auto Contains = ranges::contains; constexpr auto Copy = ranges::copy; constexpr auto Count = ranges::count; constexpr auto CountIf = ranges::count_if; constexpr auto Fill = ranges::fill; constexpr auto Find = ranges::find; constexpr auto FindIf = ranges::find_if; constexpr auto FoldLeft = ranges::fold_left; constexpr auto FoldRight = ranges::fold_right; constexpr auto IsSorted = ranges::is_sorted; constexpr auto IsSortedUntil = ranges::is_sorted_until; constexpr auto LowerBound = ranges::lower_bound; constexpr auto Max = ranges::max; constexpr auto MaxElement = ranges::max_element; constexpr auto Min = ranges::min; constexpr auto MinElement = ranges::min_element; constexpr auto MinMax = ranges::minmax; constexpr auto MinMaxElement = ranges::minmax_element; constexpr auto Reverse = ranges::reverse; constexpr auto Rotate = ranges::rotate; constexpr auto Sort = ranges::sort; constexpr auto UpperBound = ranges::upper_bound; template constexpr auto Adjacent = views::adjacent; constexpr auto Chunk = views::chunk; constexpr auto Drop = views::drop; constexpr auto DropWhile = views::drop_while; constexpr auto Enumerate = views::enumerate; constexpr auto Filter = views::filter; constexpr auto Join = views::join; constexpr auto Slide = views::slide; constexpr auto Stride = views::stride; constexpr auto Take = views::take; constexpr auto TakeWhile = views::take_while; constexpr auto Zip = views::zip; constexpr auto Rev = views::reverse; // ranges の方と混同しない constexpr auto Transform = views::transform; // ranges の方は多分使わない constexpr auto Iota = views::iota; // ranges の方は多分使わない constexpr auto rtov = ranges::to(); constexpr auto rtos = ranges::to(); namespace rg = ranges; namespace vw = views; using namespace placeholders; } // namespace yamada // ===== END INCLUDE: ranges.hpp ===== // ===== BEGIN INCLUDE: macro.hpp ===== #define FOR_E1(x, v) for (auto&& x : v) #define FOR_E2(x, y, v) for (auto&& [x, y] : v) #define FOR_E3(x, y, z, v) for (auto&& [x, y, z] : v) #define FOR_E4(x, y, z, w, v) for (auto&& [x, y, z, w] : v) #define OVERLOAD5(a, b, c, d, e, f, ...) f #define FOR_E(...) OVERLOAD5(__VA_ARGS__, FOR_E4, FOR_E3, FOR_E2, FOR_E1)(__VA_ARGS__) #define FOR1(a) for (long long _ = 0; _ < (long long)(a); ++_) #define FOR2(i, a) for (long long i = 0; i < (long long)(a); ++i) #define FOR3(i, a, b) for (long long i = a; i < (long long)(b); ++i) #define FOR4(i, a, b, c) for (long long i = a; i < (long long)(b); i += c) #define OVERLOAD4(a, b, c, d, e, ...) e #define FOR(...) OVERLOAD4(__VA_ARGS__, FOR4, FOR3, FOR2, FOR1)(__VA_ARGS__) #define FOR_R1(a) for (long long i = (long long)(a)-1; i >= 0LL; --i) #define FOR_R2(i, a) for (long long i = (long long)(a)-1; i >= 0LL; --i) #define FOR_R3(i, a, b) for (long long i = (long long)(b)-1; i >= (long long)(a); --i) #define OVERLOAD3(a, b, c, d, ...) d #define FOR_R(...) OVERLOAD3(__VA_ARGS__, FOR_R3, FOR_R2, FOR_R1)(__VA_ARGS__) #define eb emplace_back #define pb push_back #define fi first #define se second #define VV(type, name, h, ...) \ vector> name(h, vector(__VA_ARGS__)) #define VVV(type, name, h, w, ...) \ vector>> name( \ h, vector>(w, vector(__VA_ARGS__))) #define VVVV(type, name, a, b, c, ...) \ vector>>> name( \ a, vector>>( \ b, vector>(c, vector(__VA_ARGS__)))) #define CHAR(...) char __VA_ARGS__; IN(__VA_ARGS__) #define INT(...) int __VA_ARGS__; IN(__VA_ARGS__) #define LL(...) long long __VA_ARGS__; IN(__VA_ARGS__) #define STR(...) std::string __VA_ARGS__; IN(__VA_ARGS__) #define ZIN(...) for (auto&& [__VA_ARGS__] : std::views::zip(__VA_ARGS__)) IN(__VA_ARGS__) #define DIE(...) do { yamada::OUT(__VA_ARGS__); return; } while (0) // ===== END INCLUDE: macro.hpp ===== namespace yamada { void solve(); } int main() { yamada::solve(); } // ===== END INCLUDE: ../../template/template.hpp ===== void yamada::solve() { LL(N); vp xy(N); FOR_E(x,y,xy){ LL(u,v); x=(u+v)*2; y=(u-v)*2; } Sort(xy,{},&pl::se); auto[X0,Y0]=xy.front(); // 一番下 auto[X1,Y1]=xy.back(); // 一番上 FOR_E(x,y,xy)ERR(x,y); auto has_common=[&](ll l,ll r,ll L,ll R)->bool{ return max(l,L)<=min(r,R); }; OUT(bisect(-1,infLL,[&](ll D)->bool{ // D以下にできない場合true ll l=-infLL,r=infLL; ll L=-infLL,R=infLL; vl xs; // 余ったやつ if(Y0+Dr || L>R)return 1; if(xs.empty())return 0; Sort(xs); ll M=len(xs); FOR(m,M+1){ ll l2=(m>0? xs[m-1]-D:-infLL); ll r2=(m>0? xs[0]+D : infLL); ll L2=(mr2 || L2>R2)continue; FOR(2){ swap(l2,L2); swap(r2,R2); if(has_common(l,r,l2,r2) && has_common(L,R,L2,R2))return 0; } } return 1; })); }