#ifdef NACHIA #define _GLIBCXX_DEBUG #else #define NDEBUG #endif #include #include #include #include using i64 = long long; using u64 = unsigned long long; #define rep(i,n) for(int i=0; i void chmin(A& l, const A& r){ if(r < l) l = r; } template void chmax(A& l, const A& r){ if(l < r) l = r; } using namespace std; #include using Modint = atcoder::static_modint<998244353>; void testcase(){ i64 N; cin >> N; i64 K; cin >> K; K *= 2; K += N; vector A(N); rep(i,N) cin >> A[i]; sort(A.begin(), A.end()); vector L(N), R(N,N); i64 ans = 0; for(i64 b=29; b>=0; b--){ vector M(N); rep(i,N) M[i] = lower_bound(A.begin(), A.end(), ((A[i] ^ ans) & ~((1ll << b) - 1)) | (1ll << b)) - A.begin(); i64 k = 0; rep(i,N){ if(A[i] & (1ll << b)) k += R[i] - M[i]; else k += M[i] - L[i]; } //cout << "ans = " << ans << " , k = " << k << endl; if(k < K){ rep(i,N) ((A[i] & (1ll << b)) ? R[i] : L[i]) = M[i]; ans |= 1ll << b; K -= k; } else { rep(i,N) ((A[i] & (1ll << b)) ? L[i] : R[i]) = M[i]; } } cout << ans << '\n'; } int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); testcase(); return 0; }