Problem E

Statement
Copy Copied
E. Boneca Ambalabutime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputBoneca Ambalabu gives you a sequence of $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$.Output the maximum value of $$$(a_k\oplus a_1)+(a_k\oplus a_2)+\ldots+(a_k\oplus a_n)$$$ among all $$$1 \leq k \leq n$$$. Note that $$$\oplus$$$ denotes the bitwise XOR operation.InputThe first line contains an integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) – the number of independent test cases.The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n\leq 2\cdot 10^5$$$) – the length of the array.The second line of each test case contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$0 \leq a_i < 2^{30}$$$).It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.OutputFor each test case, output the maximum value on a new line.ExampleInput5318 18 1851 2 4 8 1658 13 4 5 156625 676 729 784 841 90011Output0
79
37
1555
0
NoteIn the first test case, the best we can do is $$$(18\oplus18)+(18\oplus18)+(18\oplus18)=0$$$.In the second test case, we choose $$$k=5$$$ to get $$$(16\oplus1)+(16\oplus2)+(16\oplus4)+(16\oplus8)+(16\oplus16)=79$$$.