#include #include #include #include using i64 = long long; #define rep(i,n) for(int i=0; i> N; i64 K; cin >> K; K *= 2; K += N; vector A(N); rep(i,N) cin >> A[i]; sort(A.begin(), A.end()); struct Range { i64 l, r; i64 size() const { return r-l; } }; struct RangePair { Range x0, x1; i64 size() const { return x0.size() * x1.size(); } }; auto split = [&](Range r, i64 b) -> pair { if(A[r.l] & b) return { {r.l,r.l}, r }; if(!(A[r.r-1] & b)) return { r, {r.r,r.r} }; i64 a = A[r.r-1]; i64 m = lower_bound(A.begin(), A.end(), a - (a & (b-1))) - A.begin(); return { {r.l,m}, {m,r.r} }; }; vector B; B.push_back({ 0,N,0,N }); vector L(N), R(N,N); i64 ans = 0; for(i64 d=1ll<<29; d>0; d>>=1){ vector nx0, nx1; for(auto b : B){ auto [y0,y1] = split(b.x0, d); auto [z0,z1] = split(b.x1, d); if(y0.size() != 0){ if(z0.size() != 0) nx0.push_back({ y0, z0 }); if(z1.size() != 0) nx1.push_back({ y0, z1 }); } if(y1.size() != 0){ if(z0.size() != 0) nx1.push_back({ y1, z0 }); if(z1.size() != 0) nx0.push_back({ y1, z1 }); } } i64 k = 0; for(auto& c : nx0) k += c.size(); if(k < K){ ans += d; K -= k; swap(nx0, nx1); } swap(B, nx0); } cout << ans << '\n'; } int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); testcase(); return 0; }