問題一覧 > 通常問題

No.698 Let's Form Teams in Pairs

レベル : / AI推定難易度 : 900 / 実行時間制限 : 1ケース 1.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 266
作問者 : nmnmnmnmnmnmnm
お気に入りにしたユーザー ProblemId : 2251 / 自分の提出
問題文最終更新日: 2026-06-27 21:49:32
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Back to the original

Problem Statement

$N$ players ($N$ is even) form one team and take on some kind of battle.
The combat power of the $i$-th player is $A_i$.

Each of the $N$ players must form a pair of 2 people.
When a pair is formed, its combat power becomes the bitwise XOR of the combat powers of its players.

The sum of the combat powers of all pairs is the combat power of the team.
What is the maximum combat power of the team when the pairs are chosen optimally?

Input

$N$
$A_0$ $A_1$ $\dots$ $A_{N-1}$

$N$ is a positive integer ($N$ is even). $2 \le N \le 14$.
$A_i$ is a positive integer. $1 \le A_i \le 10000000=10^7$.

Output

Output the answer on one line.
Print a newline at the end.

Sample

Sample 1
Input
4
1 2 3 4
Output
10

When the player with combat power 1 and the player with combat power 2 form a pair, the combat power of the pair is 3.
When the player with combat power 3 and the player with combat power 4 form a pair, the combat power of the pair is 7.
In this case, the combat power of the team is 10, the sum of the combat powers of the pairs, and this is the maximum.

Sample 2
Input
2
5 6
Output
3

When the player with combat power 5 and the player with combat power 6 form a pair, the combat power is 3.
Forming a pair may make the combat power lower than that of the individual players.
However, the players must form pairs.

Sample 3
Input
10
387 137 192 123 29 193 753 210 821 437
Output
2728

提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。