Hide

Problem A
AND Permutation

You are given a sequence of n distinct nonnegative integers a1,a2,,an.

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

Find a permutation b1,b2,,bn of a1,a2,,an such that bi & ai=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 (1n<218), which is the number of integers in the permutation.

Each of the next n lines contains an integer ai (0ai<260), which is the input sequence, in order of i. All of the ai’s are guaranteed to be distinct. For all nonnegative numbers x, if there is some i such that ai & x=x, then there is a j such that aj=x.

Output

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

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

Please log in to submit a solution to this problem

Log in