#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; } int main() { ios::sync_with_stdio(false); cin.tie(0); int n; ll k; cin >> n >> k; VI a(n); rep(i, n) cin >> a[i]; sort(all(a)); k = 2 * k + n; int ans = 0; struct S { int l1, r1, l2, r2; }; vector d{S{0, n, 0, n}}, nd; rrep(i, 30) { auto get_mid = [&](int l, int r) -> int { assert(l < r); return ranges::lower_bound(a.begin() + l, a.begin() + r, a[l] >> i | 1, {}, [&](int x) { return x >> i; }) - a.begin(); }; ll cnt = 0; for (auto [l1, r1, l2, r2] : d) { int c1 = get_mid(l1, r1), c2 = get_mid(l2, r2); cnt += ll(c1 - l1) * (c2 - l2) + ll(r1 - c1) * (r2 - c2); } nd.clear(); if (cnt >= k) { for (auto [l1, r1, l2, r2] : d) { int c1 = get_mid(l1, r1), c2 = get_mid(l2, r2); if (l1 < c1 && l2 < c2) nd.emplace_back(l1, c1, l2, c2); if (c1 < r1 && c2 < r2) nd.emplace_back(c1, r1, c2, r2); } } else{ ans |= 1 << i; k -= cnt; for (auto [l1, r1, l2, r2] : d) { int c1 = get_mid(l1, r1), c2 = get_mid(l2, r2); if (l1 < c1 && c2 < r2) nd.emplace_back(l1, c1, c2, r2); if (c1 < r1 && l2 < c2) nd.emplace_back(c1, r1, l2, c2); } } swap(d, nd); } cout << ans << '\n'; }