Codeforces Round 618 (Div. 2)
C
Anu Has a Function
Codeforces
未评级
原题
← BD →
翻译中…

Anu has created her own function $f$: $f(x, y) = (x | y) - y$ where $|$ denotes the bitwise OR operation. For example, $f(11, 6) = (11|6) - 6 = 15 - 6 = 9$. It can be proved that for any nonnegative numbers $x$ and $y$ value of $f(x, y)$ is also nonnegative.

翻译中…

She would like to research more about this function and has created multiple problems for herself. But she isn't able to solve all of them and needs your help. Here is one of these problems.

翻译中…

A value of an array $[a_1, a_2, \dots, a_n]$ is defined as $f(f(\dots f(f(a_1, a_2), a_3), \dots a_{n-1}), a_n)$ (see notes). You are given an array with not necessarily distinct elements. How should you reorder its elements so that the value of the array is maximal possible?

翻译中…

Input

翻译中…

The first line contains a single integer $n$ ($1 \le n \le 10^5$).

翻译中…

The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($0 \le a_i \le 10^9$). Elements of the array are not guaranteed to be different.

翻译中…

Output

翻译中…

Output $n$ integers, the reordering of the array with maximum value. If there are multiple answers, print any.

翻译中…

Note

翻译中…

In the first testcase, value of the array $[11, 6, 4, 0]$ is $f(f(f(11, 6), 4), 0) = f(f(9, 4), 0) = f(9, 0) = 9$.

翻译中…

$[11, 4, 0, 6]$ is also a valid answer.

翻译中…

样例

Input #1
4
4 0 11 6
Output #1
11 6 4 0
InputCopy OutputCopy
Input #2
1
13
Output #2
13
InputCopy OutputCopy
题目信息
题号
1300C
时间限制
1 s
内存限制
256 MB

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。