Mislav and Marin learned about permutations in their combinatorics class, and they invented an interesting
game where the player must guess certain permutations that meet certain conditions. A permutation of
order
The game is played as follows. Marin first chooses zero or more conditions and one permutation
This is an interactive task. Write a program that will play the game instead of Mislav. Your program
must, for a given permutation
Constraints
Subtask | Points | Constraints |
---|---|---|
1 | 9 | |
2 | 18 | |
3 | 22 | |
4 | 51 |
Interaction
Before the interaction, your program must read from the standard input the following: The first line of
input contains the integer
After this, your program can send Marin queries by writing to the standard output. Each query must
be printed in its own line in the form of query q1 q2 ... qn
where
When your program has found a solution, it must output a line to the standard output containing the
command end
, then a line of the form of a1 a2 ... an
containing the required lexicographically smallest
permutation and a line of the form of b1 b2 ... bn
containing the required lexicographically largest
permutation. In the end, the program must flush the output again and terminate the execution.
Sample Interaction
In the following interaction sample, the first column contains the data that your program outputs to the standard output, and the second column contains the data that your program reads from the standard input. After three steps of the game, i.e. after three queries, the program determines the correct solution.
>>>
denotes your output. Do not print this out.
The chosen secret conditions are
4
3 2 1 4
>>> query 2 3 1 4
0
>>> query 3 2 4 1
0
>>> query 4 1 2 3
1
>>> end
>>> 2 1 3 4
>>> 4 3 1 2
Explanation
For the first query, condition
For the second query, condition
For the third and final query, both conditions are met.
Comments