#include #include #include #include using namespace std; class TrieNode { public: TrieNode* children[2]; TrieNode() { children[0] = nullptr; children[1] = nullptr; } }; class Trie { private: TrieNode* root; public: Trie() { root = new TrieNode(); } void insert(int num) { TrieNode* node = root; for (int i = 31; i >= 0; --i) { // Assuming 32-bit integers int bit = (num >> i) & 1; if (!node->children[bit]) { node->children[bit] = new TrieNode(); } node = node->children[bit]; } } int findMinXor(int num) { TrieNode* node = root; int xorValue = 0; for (int i = 31; i >= 0; --i) { int bit = (num >> i) & 1; // Prefer to go in the opposite direction for minimum XOR if (node->children[1 - bit]) { xorValue |= (1 << i); node = node->children[1 - bit]; } else { node = node->children[bit]; } } return xorValue; } }; int main() { int N, K; cin >> N >> K; // Read size of array and position K vector A(N); // Read array elements for (int i = 0; i < N; ++i) { cin >> A[i]; } set uniqueXors; // To store unique XOR results Trie trie; // Insert first element into trie trie.insert(A[0]); // Calculate all Ai ⊕ Aj for 1 ≤ i < j ≤ N using trie for (int i = 1; i < N; ++i) { int minXor = trie.findMinXor(A[i]); uniqueXors.insert(minXor); trie.insert(A[i]); // Insert current element into trie } // Convert set to vector and sort it vector sortedResults(uniqueXors.begin(), uniqueXors.end()); // Output the K-th value (1-based index) cout << sortedResults[K - 1] << endl; return 0; }