In Ethan's room, he keeps his prized permutation of the integers from
to
in sorted order.
Unfortunately last night he forgot to close the door of his pet birds' cages. While he slept, the birds have escaped and shuffled !
Luckily, Ethan has figured out a way to get the birds to restore to its sorted state.
In a given instruction, Ethan can direct
birds to each pick up an element of
, and then get the birds to reverse their order. In particular, the leftmost bird will swap with the rightmost bird and so on down the order.
More formally Ethan can select integers
, and the following assignments all occur simultaneously:
Our goal is to sort the permutation into increasing order using repeated instructions given to the birds.
However, it's unclear how long Ethan can get the birds to listen to his instructions. As such, try to minimize the maximum number of instructions that Ethan will have to give.
Constraints
It is guaranteed that the will form a permutation.
Subtask 1 [50%]
is a power of two.
Subtask 2 [15%]
Subtask 3 [10%]
Subtask 4 [25%]
No additional constraints.
Scoring
Let be the maximum number of operations used in any test-case in a subtask.
For each subtask, the following table denotes the percentage of the total value of that subtask your solution will recieve:
M | Score (Subtask 1) | Score (Other Subtasks) |
---|---|---|
Input Specification
The first line of input consists of a single integer .
The second line of each test case contains integers
: the permutation to sort.
Output Specification
The first line of output contains a single integer : the number of operations you used.
Then follow lines of output.
The -st line of output contains a binary string of length
:
.
If the -th character of
is
1
, then is an index in the
-th operation (and the opposite if the
-th character is
0
).
Sample Input 1
4
1 3 4 2
Sample Output 1
4
1110
0100
0011
1111
Sample Explanation 1
After the first operation, the permutation is 4 3 1 2
.
After the second operation, the permutation is 4 3 1 2
.
After the third operation, the permutation is 4 3 2 1
.
After the fourth operation, the permutation is 1 2 3 4
--- sorted order.
Sample Input 2
8
1 2 3 4 5 6 7 8
Sample Output 2
0
Note
If your output contains more than operations you may get a verdict of
Output Limit Exceeded
instead of the expected 0 point partial.
Comments