#P1163E. Magical Permutation
Magical Permutation
Description
Kuro has just learned about permutations and he is really excited to create a new permutation type. He has chosen distinct positive integers and put all of them in a set . Now he defines a magical permutation to be:
- A permutation of integers from to , where is a non-negative integer.
- The bitwise xor of any two consecutive elements in the permutation is an element in .
Since Kuro is really excited about magical permutations, he wants to create the longest magical permutation possible. In other words, he wants to find the largest non-negative integer such that there is a magical permutation of integers from to . Since he is a newbie in the subject, he wants you to help him find this value of and also the magical permutation for that .
The first line contains the integer () — the number of elements in the set .
The next line contains distinct integers () — the elements in the set .
In the first line print the largest non-negative integer , such that there is a magical permutation of integers from to .
Then print integers describing a magical permutation of integers from to . If there are multiple such magical permutations, print any of them.
Input
The first line contains the integer () — the number of elements in the set .
The next line contains distinct integers () — the elements in the set .
Output
In the first line print the largest non-negative integer , such that there is a magical permutation of integers from to .
Then print integers describing a magical permutation of integers from to . If there are multiple such magical permutations, print any of them.
Note
In the first example, is a magical permutation since:
Where denotes bitwise xor operation.