Today, as a friendship gift, Bakry gave Badawy n n n integers a 1 , a 2 , … , a n a_1,a_2,…,a_n a1,a2,…,an and challenged him to choose an integer X X X such that the value m a x 1 ≤ i ≤ n ( a i ⊕ X ) \underset{1≤i≤n}{max}(a_i⊕X) 1≤i≤nmax(ai⊕X) is minimum possible, where ⊕ ⊕ ⊕ denotes the bitwise XOR operation.
As always, Badawy is too lazy, so you decided to help him and find the minimum possible value of m a x 1 ≤ i ≤ n ( a i ⊕ X ) \underset{1≤i≤n}{max}(a_i⊕X) 1≤i≤nmax(ai⊕X)
Input
The first line contains integer n ( 1 ≤ n ≤ 1 0 5 ) n (1≤n≤10^5) n(1≤n≤105).
The second line contains n n n integers a 1 , a 2 , … , a n ( 0 ≤ a i ≤ 2 30 − 1 ) a_1,a_2,…,a_n (0≤a_i≤2^{30}−1) a1,a2,…,an(0≤ai≤230−1).
Output
Print one integer — the minimum possible value of m a x 1 ≤ i ≤ n ( a i ⊕ X ) \underset{1≤i≤n}{max}(a_i⊕X) 1≤i≤nmax(ai⊕X)
Examples
input
3
1 2 3
output
2
input
2
1 5
output
4
Note
In the first sample, we can choose X = 3 X=3 X=3.
In the second sample, we can choose X = 5 X=5 X=5.
#include <bits/stdc++.h>
using namespace std;
const int maxn=1e5+10;
int n;
int trie[maxn*32][3],cnt=1,ans;
void insert(int x) {
int p = 1;
for (int i = 30; i >= 0; i--) {
int now = (x >> i) & 1;
if (!trie[p][now]) {
trie[p][now] = ++cnt;
}
p = trie[p][now];
}
}
int search(int cnt,int now) {
if (cnt == -1) return 0;
if (trie[now][0] == 0) {
search(cnt - 1, trie[now][1]);
} else if (trie[now][1] == 0) {
search(cnt - 1, trie[now][0]);
} else {
return (1 << cnt) + min(search(cnt - 1, trie[now][0]), search(cnt - 1, trie[now][1]));
}
}
int main() {
scanf("%d", &n);
for (int i = 1, x; i <= n; i++) {
scanf("%d", &x);
insert(x);
}
printf("%d\n", search(30, 1));
}