Lexicographically Maximum
InterviewTime limit1sMemory limit1024 MB
Bits in the same position can be swapped between any two numbers, so find the lexicographically largest array reachable after any number of swaps.
- Level
Medium4 of 10
- Topics
- Bit manipulation, Greedy
- Solved
- No attempts yet
Problem
A list of integers is stored in the memory of an electronic device. The device has a peculiar operation: bit swapping between numbers. Given integers , and , this operation swaps the -th bit of with the -th bit of (and vice versa).
Very interesting phenomena can occur when this operation is performed one or more times, such as obtaining numbers that did not belong to the original list, or numbers larger or smaller than all the original elements.
Use the operation as many times as needed so that the resulting list is lexicographically maximum: is as large as possible, is as large as possible among the lists that maximize , and so on.
Input
The first line contains an integer (). The second line contains integers separated by spaces, the list ().
Output
Print a single line with integers separated by spaces, the lexicographically maximum sequence that can be obtained.