100 atcoder#ABC197C. [ABC197C] ORXOR

[ABC197C] ORXOR

Score : 300300 points

Problem Statement

Given is a number sequence AA of length NN. Let us divide this sequence into one or more non-empty contiguous intervals. Then, for each of these intervals, let us compute the bitwise OR\mathrm{OR} of the numbers in it. Find the minimum possible value of the bitwise XOR\mathrm{XOR} of the values obtained in this way.

What is bitwise $\mathrm{OR}$?

The bitwise OR\mathrm{OR} of integers AA and BB, A OR BA\ \mathrm{OR}\ B, is defined as follows:

  • When A OR BA\ \mathrm{OR}\ B is written in base two, the digit in the 2k2^k's place (k0k \geq 0) is 11 if at least one of AA and BB is 11, and 00 otherwise.

For example, we have 3 OR 5=73\ \mathrm{OR}\ 5 = 7 (in base two: 011 OR 101=111011\ \mathrm{OR}\ 101 = 111).
Generally, the bitwise OR\mathrm{OR} of kk integers p1,p2,p3,,pkp_1, p_2, p_3, \dots, p_k is defined as $(\dots ((p_1\ \mathrm{OR}\ p_2)\ \mathrm{OR}\ p_3)\ \mathrm{OR}\ \dots\ \mathrm{OR}\ p_k)$. We can prove that this value does not depend on the order of p1,p2,p3,pkp_1, p_2, p_3, \dots p_k.

What is bitwise $\mathrm{XOR}$?

The bitwise XOR\mathrm{XOR} of integers AA and BB, A XOR BA\ \mathrm{XOR}\ B, is defined as follows:

  • When A XOR BA\ \mathrm{XOR}\ B is written in base two, the digit in the 2k2^k's place (k0k \geq 0) is 11 if exactly one of AA and BB is 11, and 00 otherwise.

For example, we have 3 XOR 5=63\ \mathrm{XOR}\ 5 = 6 (in base two: 011 XOR 101=110011\ \mathrm{XOR}\ 101 = 110).
Generally, the bitwise XOR\mathrm{XOR} of kk integers p1,p2,p3,,pkp_1, p_2, p_3, \dots, p_k is defined as $(\dots ((p_1\ \mathrm{XOR}\ p_2)\ \mathrm{XOR}\ p_3)\ \mathrm{XOR}\ \dots\ \mathrm{XOR}\ p_k)$. We can prove that this value does not depend on the order of p1,p2,p3,pkp_1, p_2, p_3, \dots p_k.

Constraints

  • 1N201 \le N \le 20
  • 0Ai<2300 \le A_i \lt 2^{30}
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

NN

A1A_1 A2A_2 A3A_3 \dots ANA_N

Output

Print the answer.

3
1 5 7
2

If we divide [1,5,7][1, 5, 7] into [1,5][1, 5] and [7][7], their bitwise OR\mathrm{OR}s are 55 and 77, whose XOR\mathrm{XOR} is 22. It is impossible to get a smaller result, so we print 22.

3
10 10 10
0

We should divide this sequence into [10][10] and [10,10][10, 10].

4
1 3 3 1
0

We should divide this sequence into [1,3][1, 3] and [3,1][3, 1].