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.
N teams enter the Superbull. Each team gets an integer ID between 1 and 230−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 12 plays the team with ID 20, that game produces 24 points, because 01100 XOR 10100=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.
The first line contains the number of teams N. (1≤N≤2000)
Each of the next N lines contains one team ID. The IDs are distinct integers between 1 and 230−1.
Print the maximum total number of points that can be scored in the Superbull, on one line.
The bitwise exclusive or (XOR) compares two integers bit by bit in binary. A result bit is 1 when exactly one of the two input bits is 1, and 0 when both are 0 or both are 1. For example, 10100 (decimal 20) XOR 01100 (decimal 12) =11000 (decimal 24). Many languages write this operation with the ^ operator.