#K48162. Lexicographically Smallest Sequence with Unique Zero XOR Subarray

    ID: 28360 Type: Default 1000ms 256MiB

Lexicographically Smallest Sequence with Unique Zero XOR Subarray

Lexicographically Smallest Sequence with Unique Zero XOR Subarray

You are given a sequence of n non-negative integers. Your task is to determine whether it is possible to rearrange these integers such that the XOR (exclusive OR) of all elements in the sequence is zero. If it is possible, output the lexicographically smallest sequence (i.e. sorted in non-decreasing order); otherwise, output -1.

Recall that the XOR (\(\oplus\)) operation satisfies:

[ a \oplus b = c \quad \text{if and only if the binary representation of } c \text{ is computed bitwise from } a \text{ and } b.]

Note: The problem expects that the entire sequence, when taken as a single subarray, should have an XOR sum of zero. In other words, if \(a_1, a_2, \ldots, a_n\) denote your sequence, then \(a_1 \oplus a_2 \oplus \ldots \oplus a_n = 0\) should hold.

If this condition is not met, output -1.

inputFormat

The input is read from stdin and consists of two lines.

  • The first line contains an integer \(n\) (\(1 \le n \le 10^5\)), representing the number of integers.
  • The second line contains \(n\) space-separated non-negative integers.

outputFormat

Output the lexicographically smallest arrangement (i.e. the sorted sequence) of the given integers if the XOR of the entire sequence equals zero. Otherwise, output -1.

All outputs should be printed to stdout.

## sample
4
1 2 3 0
0 1 2 3