E - Rearrange and Adjacent XOR Editorial /

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 800800

問題文

長さ NN の非負整数列 A=(A1,A2,,AN)A=(A_1,A_2,\dots,A_N) が与えられます。この整数列に対して以下の操作を N1N-1 回行って長さ 11 の整数列を得ることを考えます。

  • nnAA の長さとする。はじめに AA 内の要素を好きなように並び替える。 その後、 AA を長さ n1n-1 の非負整数列 (A1A2,A2A3,,An1An)(A_1 \oplus A_2, A_2 \oplus A_3, \dots, A_{n-1} \oplus A_n) に置き換える

ただしここで、 \oplus はビット単位 XOR\mathrm{XOR} 演算を表します。

N1N-1 回の操作後に得られる長さ 11 の整数列が含む項の値を XX としたとき、XX として考えられる値の最大値を求めてください。

ビット単位 XOR\mathrm{XOR} 演算とは

非負整数 A,BA, B のビット単位 XOR\mathrm{XOR}ABA \oplus B は、以下のように定義されます。

  • ABA \oplus B を二進表記した際の 2k2^k (k0k \geq 0) の位の数は、A,BA, B を二進表記した際の 2k2^k の位の数のうち一方のみが 11 であれば 11、そうでなければ 00 である。
例えば、35=63 \oplus 5 = 6 となります (二進表記すると: 011101=110011 \oplus 101 = 110)。
一般に kk 個の非負整数 p1,p2,p3,,pkp_1, p_2, p_3, \dots, p_k のビット単位 XOR\mathrm{XOR}(((p1p2)p3)pk)(\dots ((p_1 \oplus p_2) \oplus p_3) \oplus \dots \oplus p_k) と定義され、これは p1,p2,p3,,pkp_1, p_2, p_3, \dots, p_k の順番によらないことが証明できます。

制約

  • 2N1002 \leq N \leq 100
  • 0Ai<2600 \leq A_i < 2^{60}
  • 入力される値はすべて整数

入力

入力は以下の形式で標準入力から与えられる。

NN
A1A_1 A2A_2 \dots ANA_N

出力

答えを出力せよ。


入力例 1Copy

Copy
4
1 2 3 4

出力例 1Copy

Copy
7

以下のような 33 回の操作により AAA=(7)A=(7) とできます。

  • 11 回目の操作にて、 A=(1,2,3,4)A=(1,2,3,4)(3,1,4,2)(3,1,4,2) と並び替える。 AA(31,14,42)=(2,5,6)(3 \oplus 1, 1 \oplus 4, 4 \oplus 2) = (2,5,6) に置き換わる。
  • 22 回目の操作にて、 A=(2,5,6)A=(2,5,6)(2,6,5)(2,6,5) と並び替える。 AA(26,65)=(4,3)(2 \oplus 6, 6 \oplus 5) = (4,3) に置き換わる。
  • 33 回目の操作にて、 A=(4,3)A=(4,3)(4,3)(4,3) と並び替える。 AA(43)=(7)(4 \oplus 3) = (7) に置き換わる。

入力例 2Copy

Copy
13
451745518671773958 43800508384422957 153019271028231120 577708532586013562 133532134450358663 619750463276496276 615201966367277237 943395749975730789 813856754125382728 705285621476908966 912241698686715427 951219919930656543 124032597374298654

出力例 2Copy

Copy
1152905479775702586

Score: 800800 points

Problem Statement

You are given a sequence of NN non-negative integers A=(A1,A2,,AN)A=(A_1,A_2,\dots,A_N). Consider performing the following operation N1N-1 times on this sequence to obtain a sequence of length 11:

  • Let nn be the length of AA. First, rearrange the elements in AA in any order you like. Then, replace AA with a sequence of n1n-1 non-negative integers (A1A2,A2A3,,An1An)(A_1 \oplus A_2, A_2 \oplus A_3, \dots, A_{n-1} \oplus A_n).

Here, \oplus represents the bitwise XOR\mathrm{XOR} operation.

Let XX be the value of the term contained in the sequence of length 11 obtained after N1N-1 operations. Find the maximum possible value of XX.

What is the bitwise XOR\mathrm{XOR} operation?

The bitwise XOR\mathrm{XOR} of two non-negative integers AA and BB, denoted as ABA \oplus B, is defined as follows:

  • In the binary representation of ABA \oplus B, the digit at the 2k2^k (k0k \geq 0) position is 11 if the digit at the 2k2^k position is 11 in AA or BB but not both, and 00 otherwise.
For example, 35=63 \oplus 5 = 6 (in binary: 011101=110011 \oplus 101 = 110).
In general, the bitwise XOR\mathrm{XOR} of kk non-negative integers p1,p2,p3,,pkp_1, p_2, p_3, \dots, p_k is defined as (((p1p2)p3)pk)(\dots ((p_1 \oplus p_2) \oplus p_3) \oplus \dots \oplus p_k), and it can be proved that this does not depend on the order of p1,p2,p3,,pkp_1, p_2, p_3, \dots, p_k.

Constraints

  • 2N1002 \leq N \leq 100
  • 0Ai<2600 \leq A_i < 2^{60}
  • All input values are integers.

Input

The input is given from Standard Input in the following format:

NN
A1A_1 A2A_2 \dots ANA_N

Output

Print the answer.


Sample Input 1Copy

Copy
4
1 2 3 4

Sample Output 1Copy

Copy
7

The sequence AA can be transformed into A=(7)A=(7) by the following three operations:

  • In the first operation, rearrange A=(1,2,3,4)A=(1,2,3,4) to (3,1,4,2)(3,1,4,2). AA is replaced with (31,14,42)=(2,5,6)(3 \oplus 1, 1 \oplus 4, 4 \oplus 2) = (2,5,6).
  • In the second operation, rearrange A=(2,5,6)A=(2,5,6) to (2,6,5)(2,6,5). AA is replaced with (26,65)=(4,3)(2 \oplus 6, 6 \oplus 5) = (4,3).
  • In the third operation, rearrange A=(4,3)A=(4,3) to (4,3)(4,3). AA is replaced with (43)=(7)(4 \oplus 3) = (7).

Sample Input 2Copy

Copy
13
451745518671773958 43800508384422957 153019271028231120 577708532586013562 133532134450358663 619750463276496276 615201966367277237 943395749975730789 813856754125382728 705285621476908966 912241698686715427 951219919930656543 124032597374298654

Sample Output 2Copy

Copy
1152905479775702586


2025-04-14 (Mon)
20:40:26 +00:00