Permuting cows
题号:NC17401
时间限制:C/C++/Rust/Pascal 3秒,其他语言6秒
空间限制:C/C++/Rust/Pascal 512 M,其他语言1024 M
64bit IO Format: %lld

题目描述

Niuniu likes cows. He has n cows in his farm. He loves the cows very much, but the cows seem unhappy. Niuniu figures out why this happens. The cows are arranged in a sequence. Two cows may become unhappy when they are adjacent in the sequence. Every cow has a characteristic value, named vi. The unhappiness between cow i and i+1 is defined as vi xor vi+1. (xor is exclusive OR) Niuniu wants the largest unhappiness between each pair of adjacent cows to be as low as possible. You need to tell him a permutation pi, so that when the i-th position is the pi-th cow in the new sequence, the largest unhappiness is as low as possible. Among all the permutations, you need to tell him the lexicographically smallest one.

输入描述:

The first line contains one integer n, which is the number of cows. The second line contains n integers, v1 v2 … vn, separated by a space. (2 ≤ n ≤ 300000, 0 ≤ vi ≤ 1000000000)

输出描述:

Print a single line with n numbers, which means the permutation.
示例1

输入

复制
8
1 9 2 6 0 8 1 7

输出

复制
1 2 6 5 3 4 7 8

备注:

This problem contains a large number of testcases.  Please, check your code carefully before you submit and wait patiently for the result.