#P17127. [ICPC 2025 Shanghai R] Gemcrate
[ICPC 2025 Shanghai R] Gemcrate
Problem Description
Noir has gems. The -th gem has a positive integer written on it. Noir wants to divide these gems into several non-empty groups. Each gem belongs to exactly one group.
Suppose the -th group contains gems with label , then Noir treats the brightness of the -th group as $a_{k_{i,1}} \oplus a_{k_{i,2}} \oplus \cdots \oplus a_{k_{i,p}}$, where is the bitwise-XOR operation. Denote the brightness of the -th group as .
For a grouping method of groups, Noir treats the value of this method as , where is the bitwise-AND operation.
Noir wants to find the maximum possible value over all grouping methods.
Input Format
The input contains multiple testcases. The first line of the input contains an integer (), the number of testcases.
For each testcase, the first line contains an integer (), the number of gems.
The second line contains integers (), the integers written on gems.
It’s guaranteed that the sum of over all testcases does not exceed .
Output Format
For each testcase, print an integer representing the maximum possible value over all grouping methods.
4
4
1 2 3 1
6
4 7 5 2 6 3
4
14 15 9 18
2
251508091405 13011908091815
2
6
26
13121614001578
Hint
For the first testcase, a possible grouping method is with a value of $B_1 \& B_2 = (1 \oplus 3) \& (2 \oplus 1) = 2 \& 3 = 2$. Another possible grouping method is , with a lower value . It can be proved that it’s not possible to achieve a value greater than .
For the second testcase, the best grouping method is with a value of .