codeforces#P1945H. GCD is Greater
GCD is Greater
Description
In the evenings during the hike, Kirill and Anton decided to take out an array of integers $a$ of length $n$ from their backpack and play a game with it. The rules are as follows:
- Kirill chooses from $2$ to $(n-2)$ numbers and encircles them in red.
- Anton encircles all the remaining numbers in blue.
- Kirill calculates the greatest common divisor (GCD) of all the red numbers.
- Anton calculates the bitwise AND of all the blue numbers and adds the number $x$ to the result.
- If the GCD of all the red numbers is strictly greater than the sum of the bitwise AND of all the blue numbers and the number $x$, then Kirill wins; otherwise, Anton wins.
Help Kirill to beat Anton or tell if it's impossible.
Each test consists of multiple test cases. The first line contains a single integer $t$ ($1 \le t \le 20\,000$) — the number of test cases. Then follows the description of the test cases.
The first line of each test case contains two integers $n$ and $x$ ($4\le n \le 4\cdot 10^5$, $0 \le x \le 4\cdot 10^5$) — the number of integers and the number $x$ respectively.
The second line contains an array $a$ of length $n$ ($1 \le a_i \le 4\cdot 10^5$).
It is guaranteed that the sum of $n$ for all test cases does not exceed $4\cdot 10^5$. It is also guaranteed that the sum of the maximum values of $a_i$ for each test case does not exceed $4\cdot 10^5$.
For each test case, output "YES" on the first line if the condition can be met, on the second line, output the number of chosen numbers by Kirill and the numbers themselves in any order separated by a space, and on the third line, output the size of the second set and the numbers in it.
Otherwise, output "NO".
You can output each letter in any case (lowercase or uppercase). For example, the strings "yEs", "yes", "Yes", and "YES" will be accepted as a positive answer.
Input
Each test consists of multiple test cases. The first line contains a single integer $t$ ($1 \le t \le 20\,000$) — the number of test cases. Then follows the description of the test cases.
The first line of each test case contains two integers $n$ and $x$ ($4\le n \le 4\cdot 10^5$, $0 \le x \le 4\cdot 10^5$) — the number of integers and the number $x$ respectively.
The second line contains an array $a$ of length $n$ ($1 \le a_i \le 4\cdot 10^5$).
It is guaranteed that the sum of $n$ for all test cases does not exceed $4\cdot 10^5$. It is also guaranteed that the sum of the maximum values of $a_i$ for each test case does not exceed $4\cdot 10^5$.
Output
For each test case, output "YES" on the first line if the condition can be met, on the second line, output the number of chosen numbers by Kirill and the numbers themselves in any order separated by a space, and on the third line, output the size of the second set and the numbers in it.
Otherwise, output "NO".
You can output each letter in any case (lowercase or uppercase). For example, the strings "yEs", "yes", "Yes", and "YES" will be accepted as a positive answer.
8
4 1
4 3 1 8
4 1
4 5 8 4
5 0
1 1 1 1 1
5 2
31 63 127 63 31
4 1
1 3 3 3
8 3
4 3 4 1 2 2 5 3
4 2
1 4 3 6
8 48
31 61 37 15 53 26 61 12
YES
2 4 8
2 3 1
YES
2 4 4
2 5 8
NO
YES
2 63 63
3 31 127 31
YES
2 3 3
2 1 3
YES
2 4 4
6 3 1 2 2 5 3
YES
2 3 6
2 1 4
YES
2 61 61
6 31 37 15 53 26 12