C. A Good Problem
Problem Statement
You are given four positive integers . You need to find the lexicographically smallest* array of length , consisting of integers, such that:
- For every , .
- , where denotes the bitwise AND operation and denotes the bitwise XOR operation.
If no such array exists, output . Otherwise, since the entire array might be too large to output, output only.
Note: An array is lexicographically smaller than an array if and only if one of the following holds:
- is a prefix of , but ; or
- In the first position where and differ, the array has a smaller element than the corresponding element in .
Input
Each test contains multiple test cases. The first line contains the number of test cases . The description of the test cases follows.
Each test case contains four positive integers .
Output
For each test case, output or if no array meets the conditions.
Solution
If is odd, we can construct the array with all elements equal to .
Then we can think what happens if is even. In this case, we can have elements equal to which means the & operation will be but the xor operation will be .
The last two elements should satisfy the condition that . Consider a single bit in , if we want to keep this bit in the result , this bit should be set in both and . If both bits are set, then will be and that means they are not valid. So for all bits that are set in , we can not set them in both and . And the values and should be greater than . So we can have . In this case, and , is the smallest possible value.