#DSU0000065. Sắp xếp theo điều kiện XOR (XOUR)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Sắp xếp theo điều kiện XOR (XOUR)
XOUR
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
You are given an array of nonnegative integers . You may rearrange its elements using conditional swaps.
In one operation, choose any two positions . Let and be their current values. You may swap them only if , where XOR is the bitwise exclusive-or operation. After a swap, conditions for subsequent swaps are evaluated on the values at their new positions.
Find the lexicographically smallest array obtainable after any finite number of valid swaps. If several sequences of swaps produce the same smallest array, only the resulting array is required.
Input
The first line contains . The second contains the values .
Output
Print the values of the lexicographically smallest reachable array.
Subtasks
- Subtask 1 (20 points): , .
- Subtask 2 (30 points): , .
- Subtask 3 (50 points): , .
Examples
Input
5
2 7 1 5 6
Output
1 5 2 6 7
Explanation
Values 1 and 2 can swap, and values 5, 6, 7 can be rearranged within their group. Sorting each group of values at its original positions yields the minimum array.