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
def find(parent,x):
    if parent[x-1] == x:
         return x
    parent[x-1] = find(parent,parent[x-1])
    return parent[x-1]     
def union(rank,x,y,parent):
    x_ = find(parent,x)-1
    y_ = find(parent,y)-1
    if x_ != y_:
        if rank[x_] < rank[y_]:
            parent[x_] = y_ 
        elif rank[x_] > rank[y_]:
            parent[y_] = x_
        else:
            parent[x_] = y_
            rank[y_] += 1


def MST(edges,n,a):
    
    parent = [i for i in a]
    rank = [0 for i in range(n)]
    edges = sorted(edges,key = lambda x:x[2])
    
    i = 0
    e = 0
    ans = 0
    while e < n-1:
        u,v,w = edges[i]
        x = find(parent,u)
        y = find(parent,v)
        i += 1
        if x != y:
            e += 1
            ans+=w
            
            union(rank,x,y,parent)
    print(ans)        
n = int(input())
a = list(map(int,input().split(' ')))
edges = []
for j in range(n):
    for k in range(j+1,n):
        edges.append([a[j],a[k],a[j]^a[k]])

MST(edges,n,a)


