This is an interactive problem.
Antonia is studying the behavior of ants from a nearby colony. For her
experiment, she will place
candies in a straight line on the ground, numbered from
to
in order. She can choose the color of each candy.
From previous observations, Antonia knows that each ant leaves the colony and starts at any one of the candies. It then walks along the line, repeatedly moving from its current candy to the candy immediately to its left or right. Before returning to the colony, the ant visits every candy at least once. It may visit a candy more than once and may continue walking after it has visited every candy.
To study the routes the ants take, Antonia uses a system that records only the colors of the candies they visit, in order. She needs your help to reconstruct the sequences of visited candies from these records.
Your task is to develop a program that first chooses the colors of the candies and then reconstructs the sequences of visited candies from the recorded color sequences. For this to be possible, the coloring that you choose must ensure that no two different sequences of visited candies produce the same color sequence. We call such a coloring valid.
A valid coloring can always be obtained by using different colors, one for each candy. However, Antonia wants to use candies with as few different colors as possible.
First, read a line with an integer () indicating the number of candies.
Then output a line with an integer followed by integers (), where is the number of different colors used and is the color of candy . You must provide a valid coloring that uses the minimum number of different colors. If several such colorings exist, you may output any of them.
After that, read a line with an integer () indicating the number of recorded color sequences. Each sequence corresponds to a different ant, and all sequences use the coloring you provided. Then, repeat the following times, once per color sequence:
Read a line with an integer () followed by integers (), where is the length of the sequence of visited candies, and is the color of the -th candy in this sequence.
Output a line with integers (), where is the number of the -th candy in the sequence of visited candies.
The sum of over all recorded color sequences does not exceed .
Each color sequence is guaranteed to correspond to an ant that visits every candy at least once, moving only between neighboring candies.
The judge program is adaptive, which means that and the recorded color sequences may depend on your outputs.
Your solution will be rejected if the coloring is not valid, is not minimum, or any reconstruction is wrong. In that case the interaction may end at any time, not necessarily immediately after the incorrect output.
Indented lines are the interactor’s; the others are your program’s.
2
2 1 2
2
2 1 2
1 2
5 2 1 2 1 2
2 1 2 1 2
In this case there are candies.
The number of different colors () is minimum: with a single color, the sequences of visited candies and would produce the same color sequence. In the sample, candy has color and candy has color .
Then there are recorded color sequences, each corresponding to a different ant. Taking into account the chosen colors, the color sequence can only come from the sequence of visited candies , and the color sequence can only come from the sequence of visited candies .
4
4 1 2 3 4
1
6 2 3 4 3 2 1
2 3 4 3 2 1
Notice that this interaction would be rejected, because it uses more colors than necessary. It is included only to illustrate the interaction format.
In this case , , and . The color sequence can only come from the sequence of visited candies . The coloring is valid and the reconstruction is correct. However, a valid coloring with fewer than four colors exists for , so is not minimum.