Problem list
Log in
#usaco0181 · USACO 2014-2015 February Silver

Superbull

Gold I 2.0 s 256 MB

A total of N (1 <= N <= 2000) teams are playing in the Superbull. Each team has a distinct integer team ID in the range 1...2^30-1. The Superbull is an elimination tournament -- after every game, Farmer John chooses which team to eliminate, and the eliminated team can no longer play. The Superbull ends when only one team remains.

In any game, the combined score of the two teams always ends up being the bitwise exclusive OR (XOR) of the two team IDs. FJ wants to choose a series of games such that the total number of points scored in the Superbull is maximized. Please help Farmer John organize the matches.

Input

Line 1: N. The following N lines contain the N team IDs.

Output

The maximum possible number of points that can be scored in the Superbull.

Example 1

Input
4
3
6
9
10
Output
37

Output details: (3 XOR 9) + (6 XOR 9) + (6 XOR 10) = 10 + 15 + 12 = 37.

Source
USACO 2014-2015 February Silver
Appears in
Not part of a ladder, contest or set yet.
Accepted 0 Submissions 0 Acceptance 0% Solvers 0

Discussion

Threads about this problem. Spoilers are collapsed; wrap hints in ||double bars||.

No discussion yet. Start a thread if something here needs explaining.

Recent submissions Open with filters
Code