atcoder#ABC249G. [ABC249G] Xor Cards
[ABC249G] Xor Cards
Score : points
Problem Statement
There are cards numbered . Card has an integer written on the front and an integer written on the back.
Consider choosing one or more cards so that the exclusive logical sum of the integers written on the front of the chosen cards is at most . Find the maximum possible exclusive logical sum of the integers written on the back of the chosen cards.
What is the exclusive logical sum?
The exclusive logical sum of two integers and is defined as follows.
- The 's place () in the binary notation of is if exactly one of the 's places in the binary notation of and is ; otherwise, it is .
For example, (In binary notation: ). In general, the exclusive logical sum of integers is defined as $(\cdots ((p_1 \oplus p_2) \oplus p_3) \oplus \cdots \oplus p_k)$. We can prove that it is independent of the order of .
Constraints
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
Output
Print the maximum possible exclusive logical sum of the integers written on the back of the chosen cards when choosing one or more cards so that the exclusive logical sum of the integers written on the front of the chosen cards is at most . If it is impossible to choose cards in such way, print instead.
4 2
1 1
3 2
2 2
0 1
3
By choosing Cards and , the exclusive logical sum of the integers written on the front of them is , and that on the back of them is , which is the maximum.
1 2
3 4
-1
It is impossible to choose cards so that the condition is satisfied.
10 326872757
487274679 568989827
267359104 968688210
669234369 189421955
1044049637 253386228
202278801 233212012
436646715 769734012
478066962 376960084
491389944 1033137442
214977048 1051768288
803550682 1053605300
1064164329