ICPC North America Championship 2021

Start

2021-08-14 07:00 AKDT

ICPC North America Championship 2021

End

2021-08-14 10:30 AKDT
The end is near!
Contest is over.
Not yet started.
Contest is starting in -69 days 2:13:26

Time elapsed

3:30:00

Time remaining

0:00:00

Problem A
AND Permutation

You are given a sequence of $n$ distinct nonnegative integers $a_1, a_2, \ldots , a_ n$.

For the given sequence, it is guaranteed that for all nonnegative numbers $x$, if there is some $i$ such that $a_ i \ \& \ x = x$, then there is a $j$ such that $a_ j = x$. Here, $\& $ refers to the bitwise AND operator.

Find a permutation $b_1, b_2, \ldots , b_ n$ of $a_1, a_2, \ldots , a_ n$ such that $b_ i \ \& \ a_ i = 0$ for all $i$. If there are multiple solutions, find any such permutation. It is guaranteed that a solution always exists.

Input

The first line of input contains an integer $n$ ($1 \le n < 2^{18}$), which is the number of integers in the permutation.

Each of the next $n$ lines contains an integer $a_ i$ ($0 \le a_ i < 2^{60}$), which is the input sequence, in order of $i$. All of the $a_ i$’s are guaranteed to be distinct. For all nonnegative numbers $x$, if there is some $i$ such that $a_ i \ \& \ x = x$, then there is a $j$ such that $a_ j = x$.

Output

Output $n$ lines, each containing a single integer, which are the $b_ i$’s, in order of $i$.

Sample Input 1 Sample Output 1
6
0
1
4
5
2
6
4
6
0
2
5
1