You are given a complete undirected graph with *n* vertices. A number *a*<sub class="lower-index">*i*</sub> is assigned to each vertex, and the weight of an edge between vertices *i* and *j* is equal to *a*<sub class="lower-index">*i*</sub> *xor* *a*<sub class="lower-index">*j*</sub>.

Calculate the weight of the minimum spanning tree in this graph.
The first line contains *n* (1 ≤ *n* ≤ 200000) — the number of vertices in the graph.

The second line contains *n* integers *a*<sub class="lower-index">1</sub>, *a*<sub class="lower-index">2</sub>, ..., *a*<sub class="lower-index">*n*</sub> (0 ≤ *a*<sub class="lower-index">*i*</sub> &lt; 2<sup class="upper-index">30</sup>) — the numbers assigned to the vertices.
none
5
1 2 3 4 5
8
4
1 2 3 4
8
1
1
0
import sys, os, io
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline

def insert(x, la):
    j = 0
    for i in p:
        if x & i:
            if not G[j] >> 25:
                la += 1
                G[j] ^= la << 25
                j = la
            else:
                j = G[j] >> 25
        else:
            if not G[j] & 33554431:
                la += 1
                G[j] ^= la
                j = la
            else:
                j = G[j] & 33554431
        cnt[j] += 1
    return la

def xor_min(x, s):
    j, ans = s, 0
    for i in range(30 - len(st), -1, -1):
        if x & pow2[i]:
            if G[j] >> 25:
                j = G[j] >> 25
            else:
                ans ^= pow2[i]
                j = G[j] & 33554431
        else:
            if G[j] & 33554431:
                j = G[j] & 33554431
            else:
                ans ^= pow2[i]
                j = G[j] >> 25
    return ans

n = int(input())
a = list(map(int, input().split()))
a = list(set(a))
a.sort()
pow2 = [1]
l = 30
for _ in range(l):
    pow2.append(2 * pow2[-1])
p = pow2[::-1]
n = len(a)
G, cnt, la = [0] * 5000000, [0] * 5000000, 0
for i in a:
    la = insert(i, la)
h = l
l0 = [-1] * (la + 1)
l0[0] = 0
st = [0]
ans = 0
while st:
    i = st[-1]
    j, k = G[i] & 33554431, G[i] >> 25
    if l0[j] == -1 and l0[k] == -1 and min(cnt[j], cnt[k]):
        l = l0[i]
        m = l + cnt[j]
        r = m + cnt[k]
        ans0 = pow2[30]
        if (m - l) * (r - m) <= 5000:
            for u in range(l, m):
                au = a[u]
                for v in range(m, r):
                    ans0 = min(ans0, au ^ a[v])
        elif m - l <= r - m:
            for u in range(l, m):
                ans0 = min(ans0, xor_min(a[u], k))
        else:
            for u in range(m, r):
                ans0 = min(ans0, xor_min(a[u], j))
        ans0 |= pow2[h]
        ans += ans0
    if l0[j] == -1:
        if cnt[j] > 1:
            st.append(j)
            h -= 1
        l0[j] = l0[i]
    elif l0[k] == -1:
        if cnt[k] > 1:
            st.append(k)
            h -= 1
        l0[k] = l0[i] + cnt[j]
    else:
        st.pop()
        h += 1
print(ans)