Superbull

No attempts yetTime limit1sMemory limit256 MB

Problem

Bessie and her friends play hoofball in the annual Superbull championship, and Farmer John runs the tournament. He wants it to be as exciting as possible.

NN teams enter the Superbull. Each team gets an integer ID between 11 and 23012^{30}-1, and no two teams share an ID. The Superbull is an elimination tournament. After each game Farmer John picks which of the two teams that just played is eliminated, and an eliminated team plays no further games. The tournament ends when one team remains.

Farmer John noticed an unusual rule about the scores. In every game, the combined score of the two teams equals the bitwise exclusive or (XOR) of their IDs. For example, if the team with ID 1212 plays the team with ID 2020, that game produces 2424 points, because 0110001100 XOR 10100=1100010100 = 11000.

Farmer John considers a game more exciting when it produces more points, so he wants to arrange the games so that the total number of points scored in the whole tournament is as large as possible. He can freely choose which two teams meet in each game and which of them is eliminated. Help him find the largest possible total.

Input

The first line contains the number of teams NN. (1N20001 \le N \le 2000)

Each of the next NN lines contains one team ID. The IDs are distinct integers between 11 and 23012^{30}-1.

Output

Print the maximum total number of points that can be scored in the Superbull, on one line.

Note

The bitwise exclusive or (XOR) compares two integers bit by bit in binary. A result bit is 11 when exactly one of the two input bits is 11, and 00 when both are 00 or both are 11. For example, 1010010100 (decimal 2020) XOR 0110001100 (decimal 1212) =11000= 11000 (decimal 2424). Many languages write this operation with the ^ operator.