Deception
Time limit1sMemory limit256 MB
You divide the numbers into two nonempty groups with equal XOR to make the first group's sum as large as possible.
- Level
Medium5 of 10
- Topics
- Bit manipulation, Greedy
- Solved
- No attempts yet
Problem
Seunghyun likes tricking people. Today he wants to trick us with a sequence.
Seunghyun brought a sequence of natural numbers . He then tells us to put each element of the sequence into group X or group Y. Call the elements of X and the elements of Y . Neither group may be empty, so and .
If equals , Seunghyun pays us won.
He has tricked us so often that we do not believe him, but there is no way to lose money here, so we will try once. Given the sequence that Seunghyun presents, write a program that decides whether we can get paid, and if we can, finds the largest amount.
is the bitwise exclusive or (XOR). Write both numbers in binary, then put 1 in each position where the two bits differ and 0 where they are the same.
Input
The first line contains (). The second line contains (), separated by spaces.
Output
Print the largest amount of money you can receive on the first line. Print 0 if you cannot receive any money.