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.


-----Examples-----
Input
4
4 0 11 6

Output
11 6 4 0
Input
1
13

Output
13 


-----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.

Difficulty: interview

Starter code:

Solutions:
import sys

n = int(sys.stdin.readline().strip())
a = list(map(int, sys.stdin.readline().strip().split()))
b = a[:]
C = [0] * n
x = [0] * n
for i in range (0, 40):
    for j in range (0, n):
        x[j] = b[j] % 2
        b[j] = b[j] // 2
    if sum(x) == 1:
        for j in range (0, n):
            if x[j] == 1:
                C[j] = C[j] + 2 ** i
l = C.index(max(C))
print(" ".join(list(map(str, [a[l]]+a[0:l]+a[l+1:]))))


def main():
    import sys
    input = sys.stdin.readline

    N = int(input())
    A = list(map(int, input().split()))

    for j in range(32, -1, -1):
        flg = 0
        for i, a in enumerate(A):
            if a >> j & 1:
                flg += 1
                idx = i
                if flg == 2:
                    break
        if flg == 1:
            A[0], A[idx] = A[idx], A[0]
            print(*A)
            return
    print(*A)


def __starting_point():
    main()

__starting_point()

import sys

# inf = open('input.txt', 'r')
# reader = (line.rstrip() for line in inf)
reader = (line.rstrip() for line in sys.stdin)
input = reader.__next__

n = int(input())
a = list(map(int, input().split()))
digits = [[] for _ in range(32)]
for i, val in enumerate(a):
    shift = 0
    while val > 0:
        if val & 1:
            digits[shift].append(i)
        val >>= 1
        shift += 1

for i in reversed(list(range(32))):
    if len(digits[i]) == 1:
        idx = digits[i][0]
        a[0], a[idx] = a[idx], a[0]
        break

print(*a)

# inf.close()


n = int(input())
a = [int(i) for i in input().split()]
once = 0
twice = 2**64
for i in a:
    twice |= (once & i)
    once |= i
a = sorted([(i & ~twice,i) for i in a],reverse=True)
a = [j for i,j in a]
print(*a)



n = int(input())

a = list(map(int,input().split()))

lis = [0] * 31

for i in a:

    for j in range(31):

        if i & (2**j) > 0:
            lis[j] += 1


nmax = 0
maxind = 0
for ind,i in enumerate(a):

    for j in range(31):

        if lis[j] >= 2:

            i |= 2**j
            i -= 2**j

    if nmax < i:
        nmax = i
        maxind = ind

ans = [a[maxind]]

for i in range(n):

    if i != maxind:
        ans.append(a[i])

print(" ".join(map(str,ans)))


n=int(input())
l=list(map(int,input().split()))
d={}
for i in l:
    b=bin(i)[:1:-1]
    for j in range(len(b)):
        if int(b[j]):
            d[j]=d.get(j,[])
            d[j].append(i)
for i in range(31,-1,-1):
    if len(d.get(i,[]))==1:
        v=d[i].pop()
        print(v,end=' ')
        k=0
        for j in l:
            if j==v and k<1:k+=1
            else:print(j,end=' ')
        quit()
print(' '.join(map(str,l)))

n = int(input())
a = list(map(int, input().split()))

for d in range(29, -1, -1):
    bit = 1 << d
    count, j = 0, 0
    for i, x in enumerate(a):
        if bit & x:
            count += 1
            if count == 2:
                break
            else:
                j = i
    if count == 1:
        print(a[j], *(a[:j] + a[j+1:]))
        break
else:
    print(*a)


n=int(input())
l=list(map(int,input().split()))
cnt=[0]*30
for i in range(n):
	for j in range(30):
		if l[i]&(1<<j):
			cnt[j]+=1
options=[i for i in range(n)]
for i in range(29,-1,-1):
	newoptions=[]
	if cnt[i]==1:
		for idx in options:
			if l[idx]&(1<<i):
				newoptions.append(idx)
	if len(newoptions)>0:
		options=newoptions
print(l[options[0]],end=" ")
for i in range(n):
	if i!=options[0]:
		print(l[i],end=" ")


from collections import defaultdict


def solve(A, N):
    assert len(A) == N
    bitCover = defaultdict(int)
    for x in A:
        for i in range(32):
            if (1 << i) & x:
                bitCover[i] += 1
    # Everything that is covered will be deleted in the final result
    best = (0,)
    for j, x in enumerate(A):
        result = 0
        for i in range(32):
            if (1 << i) & x:
                if bitCover[i] == 1:
                    result += 1 << i
        best = max(best, (result, j))

    j = best[1]
    A = [A[j]] + A[:j] + A[j + 1 :]
    return ' '.join(map(str, A))


def __starting_point():
    N, = list(map(int, input().split()))
    A = list(map(int, input().split()))
    ans = solve(A, N)
    print(ans)

__starting_point()

from collections import defaultdict
n = int(input())
xs = list(map(int, input().split()))
count = defaultdict(int)
for x in xs:
    for i, b in enumerate(reversed(bin(x)[2:])):
        if b != '0':
            count[i] += 1
rm = 0
for k, v in list(count.items()):
    if v > 1:
        rm += 2 ** k

m = -1, 0
for i, x in enumerate(xs):
    if (x | rm) - rm > m[0]:
        m = ((x | rm) - rm), i

i = m[1]
xs = [xs[i]] + xs[:i] + xs[i + 1:]
print(' '.join(map(str, xs)))



n = int(input())
A = list(map(int,input().split()))

B = [[0] * 33 for i in range(n)]
C = [0] * 33
for i in range(n):
    t = A[i]
    j = 0
    while t > 0:
        B[i][j] += t%2
        C[j] += B[i][j]
        t//=2
        j += 1

M2 = [1]
for i in range(40):
    M2.append(M2[-1]*2)

S = [0] * n
for i in range(n):
    for j in range(33):
        if B[i][j] == 1:
            if C[j] == 1:
                S[i] += M2[j]

ind = S.index(max(S))
ANS = [A[ind]]
for i in range(n):
    if i != ind:
        ANS.append(A[i])
print(" ".join([str(i) for i in ANS]))

import sys
import math
from collections import defaultdict
from collections import deque
from itertools import combinations
from itertools import permutations
input = lambda : sys.stdin.readline().rstrip()
read = lambda : list(map(int, input().split()))
go = lambda : 1/0
def write(*args, sep="\n"):
  for i in args:
    sys.stdout.write("{}{}".format(i, sep))
INF = float('inf')
MOD = int(1e9 + 7)
YES = "YES"
NO = "NO"

def f(x):
  return bin(x)[2:][::-1]

n = int(input())
cnt = [0] * 100
arr = read()

for i in arr:
  s = f(i)

  for j in range(len(s)):
    if s[j] == "1":
      cnt[j] += 1

ans = [-INF, -INF]
for i in arr:
  s = f(i)

  for j in range(len(s)):
    if s[j] == "1":
      cnt[j] -= 1

  x = []
  for j in range(len(s)):
    if cnt[j] == 0:
      x.append(s[j])
    else:
      x.append("0")
  
  ans = max(ans, [int("".join(x)[::-1], 2), i])
  

  for j in range(len(s)):
    if s[j] == "1":
      cnt[j] += 1

arr.remove(ans[1])

print(ans[1], *arr)