#P10696. [SNCPC2024] 写都写了,交一发吧

[SNCPC2024] 写都写了,交一发吧

Problem Description

MCPlayer542 is solving a problem.

Since the problem is too hard, he cannot write the correct solution directly, so he wrote nn different pieces of code. The ii-th piece of code can get a score of gig_i.

Time is running out, so MCPlayer542 plans to submit code randomly. However, he then realizes that due to the special rules of this contest, he must submit code twice, and his total score will be the bitwise AND of the scores from the two submissions. Similar to the contest you are taking part in, the code submitted in the two submissions may be the same piece, or two different pieces.

Formally, if he submits the ii-th and the jj-th pieces of code in the two submissions, then the score is gi&gjg_i \& g_j, where &\& denotes the bitwise AND operation.

He wants to know the maximum score he can get.

Input Format

The input contains multiple test cases. The first line contains an integer tt (1t2×1051\le t\le 2\times 10^5), indicating the number of test cases.

For each test case, the first line contains an integer nn (1n2×1051\le n \le 2\times 10^5), indicating the number of pieces of code.

The next line contains nn integers g1, g2, , gng_1,\ g_2,\ \ldots,\ g_n (0gi<2300 \le g_i<2^{30}), separated by single spaces, with meanings as described above.

It is guaranteed that the sum of all nn does not exceed 2×1052\times 10^5.

Output Format

For each test case, output one integer per line, which is the answer.

2
3
10 4 15
4
10 10 5 4

15
10

Hint

For the first test case, just submit the third piece of code twice.

For the second test case, submit the first two pieces of code.

Translated by ChatGPT 5