Virtual contest is a way to take part in past contest, as close as possible to participation on time. It is supported only ICPC mode for virtual contests.
If you've seen these problems, a virtual contest is not for you - solve these problems in the archive.
If you just want to solve some problem from a contest, a virtual contest is not for you - solve this problem in the archive.
Never use someone else's code, read the tutorials or communicate with other person during a virtual contest.

No tag edit access

The problem statement has recently been changed. View the changes.

×
G. Xor-MST

time limit per test

2 secondsmemory limit per test

256 megabytesinput

standard inputoutput

standard outputYou are given a complete undirected graph with *n* vertices. A number *a*_{i} is assigned to each vertex, and the weight of an edge between vertices *i* and *j* is equal to *a*_{i} *xor* *a*_{j}.

Calculate the weight of the minimum spanning tree in this graph.

Input

The first line contains *n* (1 ≤ *n* ≤ 200000) — the number of vertices in the graph.

The second line contains *n* integers *a*_{1}, *a*_{2}, ..., *a*_{n} (0 ≤ *a*_{i} < 2^{30}) — the numbers assigned to the vertices.

Output

Print one number — the weight of the minimum spanning tree in the graph.

Examples

Input

5

1 2 3 4 5

Output

8

Input

4

1 2 3 4

Output

8

Codeforces (c) Copyright 2010-2022 Mike Mirzayanov

The only programming contests Web 2.0 platform

Server time: May/25/2022 19:16:22 (i2).

Desktop version, switch to mobile version.

Supported by

User lists

Name |
---|