#P16013. [ICPC 2021 NAC] AND Permutation

[ICPC 2021 NAC] AND Permutation

题目描述

You are given a sequence of nn distinct nonnegative integers a1,a2,,ana_1, a_2, \dots, a_n.

For the given sequence, it is guaranteed that for all nonnegative numbers xx, if there is some ii such that ai & x=xa_i\ \&\ x = x, then there is a jj such that aj=xa_j = x. Here, &\& refers to the bitwise AND operator.

Find a permutation b1,b2,,bnb_1, b_2, \dots, b_n of a1,a2,,ana_1, a_2, \dots, a_n such that bi & ai=0b_i\ \&\ a_i = 0 for all ii. If there are multiple solutions, find any such permutation. It is guaranteed that a solution always exists.

输入格式

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

Each of the next nn lines contains an integer aia_i (0ai<2600 \le a_i < 2^{60}), which is the input sequence, in order of ii. All of the aia_i's are guaranteed to be distinct. For all nonnegative numbers xx, if there is some ii such that ai & x=xa_i\ \&\ x = x, then there is a jj such that aj=xa_j = x.

输出格式

Output nn lines, each containing a single integer, which are the bib_i's, in order of ii.

6
0
1
4
5
2
6
4
6
0
2
5
1