No.1082 XOR of XOR
タグ : / 解いたユーザー数 374
作問者 :
Problem Statement
There is a sequence $A$ of non-negative integers with $N$ elements. The $i(1 \le i \le N)$-th element of $A$ is $A_i$.
Chawanmushi-kun performs the following operations.
- Rearrange $A$ in any order.
- Create a sequence $B$ of non-negative integers such that $B_j = A_j \oplus A_{j+1} (1 \le j \le N-1)$.
- Compute $X = B_1 \oplus B_2 \oplus B_3 \oplus \dots \oplus B_{N-1}$.
Here, $\oplus$ denotes the bitwise XOR.
* If you are not familiar with XOR, please refer to this page.
https://ja.wikipedia.org/wiki/%E6%8E%92%E4%BB%96%E7%9A%84%E8%AB%96%E7%90%86%E5%92%8C
Constraints
- $2 \le N \le 2 \times 10^3$
- $0 \le A_i \le 10^9$
- $N, A_i$ are integers
Input
$N$
$A_1\ A_2\ \dots\ A_N$
The first line ($1$) contains the integer $N$.
The second line ($2$) contains the sequence $A$ of non-negative integers, separated by spaces.
Output
Print the maximum value of $X$ on one line.
End the output with a newline.
Sample
Sample 1
Input
3
11 13 17
Output
28
The possible rearrangements of $A$ are $(11,13,17),(11,17,13),(13,11,17),(13,17,11),(17,11,13),(17,13,11)$.
Among these, when $A$ is $(13,11,17)$, $B$ becomes $(6,26)$ and $X=28$. This is the maximum value of $X$.
Also, when $A$ is $(17,11,13)$, $X=28$ as well.
Sample 2
Input
5
1 1 1 1 1
Output
0
No matter how $A$ is rearranged, $X=0$.
Sample 3
Input
8
47 36 12 71 79 85 81 74
Output
126
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。