- محدودیت زمان: ۲ ثانیه
- محدودیت حافظه: ۲۵۶ مگابایت
Everland and Neverland are two neighboring countries, and a huge number of Everlandian tourists visit Neverland every year. The governments want to analyze the passport control process in the border of Neverland and Everland, and need your help!
In the border, tourists stand in queues for their passport check, and there are passport control gates. If we number the gates from to and number the queues from to , the tourists standing in queue can only pass through gates or .
Whenever gate opens, if one of the queues and is empty or non-existent, the tourist at the front of the other queue passes through the gate. If both queues and are non-empty, the older tourist between the ones at the front of two queues passes through the gate. It is assumed that no two gates open at the same time.
We have a picture of tourists standing in queues; waiting for the gates to open. Also, we have another picture that has been taken a while later, that some of the tourists from the first picture have passed through the gates. The tourists in the pictures are numbered from to , in the order of their ages such that the person number is the youngest and the person number is the oldest. The picture below shows the first four configurations of the tourists in the first sample.
You are asked to find any valid sequence of gates’ opening that might have happened between the times the two pictures were taken, or claim that it is impossible. A gate can be opened multiple times in the sequence.
ورودی
The first line of the input contains two integers (), the number of queues, and (), the number of tourists in the first picture. The -th line of the next following lines describes queue in the first picture. Each queue description starts with a number () that shows the size of the queue, followed by integers that indicate the tourist numbers in that queue, from the back to the front. The tourist numbers are unique and non-negative integers less than . In the next following lines the description of the second picture appears in the same format.
خروجی
If there is no valid sequence, print Impossible. If there are valid sequences, output any of them in the following format. Print the length of the sequence in the first line and the sequence itself in the second line. In your sequence, every time any gate opens, there must be at least one tourist waiting for it.
مثال
ورودی نمونه ۱
خروجی نمونه ۱
ورودی نمونه ۲
خروجی نمونه ۲
ورودی نمونه ۳
خروجی نمونه ۳
ورودی نمونه ۴
خروجی نمونه ۴
ارسال پاسخ برای این سؤال