Add One
Time limit2sMemory limit1024 MB
Given n integers below 2^60, merge them all by XOR while adding one to a single group exactly once. Find the largest possible final value.
- Level
Medium7 of 10
- Topics
- Bit manipulation, Math
- Solved
- No attempts yet
Problem
You are given integers . You must perform the following operation exactly times.
- Choose two numbers and in the sequence, remove them, and add a number with the value .
This alone is boring, so at any moment you may choose one number and add one to it. You must perform this add-one operation exactly once.
Eventually only one number remains. Maximize it and print the maximum value.
Input
The first line contains a single integer ().
The second line contains integers ().
Output
Print a single line containing the maximum value of the remaining number.
Hint
In the first example, the optimal strategy is:
- Choose 1 and 2: [1, 2, 1, 2] to [1, 2, 3]
- Choose 1 and 2: [1, 2, 3] to [3, 3]
- Add one to the number 3: [3, 3] to [3, 4]
- Choose 3 and 4: [3, 4] to [7]