const int N=2e5*32+5;
const int M=2e5+10;
int rt[N],tot;
struct node{
int ch[2];
int sum;
}t[N];
int a[M];
inline void insert(int &p,int v,int i){
t[++tot]=t[p];
p=tot;
++t[p].sum;
if(i<0) return;
int c=(v>>i)&1;
insert(t[p].ch[c],v,i-1);
}
inline int qmx(int l,int r,int x){//求异或最大
int res=0;
for(int i=30;i>=0;i--){
int c=(x>>i)&1;
if(t[t[r].ch[c^1]].sum-t[t[l].ch[c^1]].sum>0){
if(l!=0) l=t[l].ch[c^1];
if(r!=0) r=t[r].ch[c^1];
res+=(1<<i);
}
else{
if(l!=0) l=t[l].ch[c];
if(r!=0) r=t[r].ch[c];
}
}
return res;
}