All problems

Problem 678

Decode XORed Permutation

Medium · 20 pts · Array, Bit Manipulation

Problem

A hidden permutation P of the numbers 1 to N, with N odd, was encoded as ENCODED[i] = P[i] XOR P[i + 1] for i from 0 to N - 2. Recover P. The XOR of all of 1..N is known, and the XOR of ENCODED[1], ENCODED[3], ENCODED[5], ... equals the XOR of P[1] to P[N-1]; XOR-ing the two gives P[0]. Every other element then follows from P[i + 1] = P[i] XOR ENCODED[i].

Input

The first line contains N (odd). The second line contains the N - 1 encoded values.

Output

Print the permutation P, separated by spaces.

Constraints

3 <= N <= 100000; N is odd; the encoding comes from a permutation of 1..N

Example input

3
3 1

Example output

1 2 3

Explanation

For N = 3 and ENCODED = 3 1, the XOR of 1, 2 and 3 is 0, and ENCODED[1] = 1 is P[1] XOR P[2], so P[0] = 0 XOR 1 = 1. Then P[1] = 1 XOR 3 = 2 and P[2] = 2 XOR 1 = 3, giving 1 2 3.

Every problem here can be used in a RelayTrixCode team match. Create a room.

Previous: Count Triplets That Can Form Two Arrays of Equal XOR Next: UTF-8 Validation