// C++ program to operate
// queries in a given set
#include <bits/stdc++.h>
using namespace std;
const int Maxbits = 30;
// Function for Query 1
void Insert(int x, int curx,
int* sz, int trie[100][2])
{
// XOR each element before
// storing it in the trie.
x = x ^ curx;
int p = 0;
// Storing xored element in the trie.
for (int i = Maxbits - 1; i >= 0; i--)
{
if (!trie[p][x >> i & 1])
trie[p][x >> i & 1] = (*sz)++;
p = trie[p][x >> i & 1];
}
}
// Function for Query 2
void XorQuery(int x, int* curx)
{
// Simply xor-ing all the number which
// was asked to xor with the set elements.
(*curx) = (*curx) ^ x;
}
// Function for Query 3
void MinXor(int x, int trie[100][2])
{
int ans = 0, p = 0;
// Finding the minimum element by checking
// if x[i] bit is same with trie element.
for (int i = Maxbits - 1; i >= 0; i--)
{
bool Currbit = (x >> i & 1);
if (trie[p][Currbit])
p = trie[p][Currbit];
else {
p = trie[p][!Currbit];
ans |= 1 << i;
}
}
cout << ans << endl;
}
// Driver code
int main()
{
int sz = 1;
int curx = 0;
int trie[100][2] = { 0 };
// Initialising the trie
Insert(0, 0, &sz, trie);
// Calling the Query
MinXor(curx, trie);
Insert(7, curx, &sz, trie);
MinXor(curx, trie);
XorQuery(4, &curx);
XorQuery(8, &curx);
XorQuery(3, &curx);
Insert(10, curx, &sz, trie);
Insert(3, curx, &sz, trie);
MinXor(curx, trie);
XorQuery(1, &curx);
return 0;
}