Maximum bit shifts

3

14 votes
Basic Programming, Bit Manipulation
Problem

You are given a sequence of N numbers. You can perform the following operation:

Select a number from the sequence and swap any pair of bits in its binary representation (Binary representation does not have any leading zeroes).

Output the lexicographic maximum sequence possible after performing 0 or more of the above operations.

Input format

  • First line: A single integer N denoting the number of integers
  • Second line: N integers denoting the array elements

Output format

Print N space-separated integers denoting the lexicographic maximum sequence possible.

Constraints

1N100000

1Ai1018

Sample Input
2
10 15
Sample Output
12 15
Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

Binary representation of 10 = 1010. Swap second and third bit to get the binary represenation as 1100 = 12.

Editor Image

?