In the event of technical difficulties with Szkopuł, please contact us via email at [email protected].

If you would like to talk about tasks, solutions or technical problems, please visit our Discord servers. They are moderated by the community, but members of the support team are also active there.

A gambling machine consists of generators of integers: , where . The generator can generate integers only from the certain set , or which means that the game is over. The can be an empty set. Let be the number of elements of the set . The sum of all the integers , for , cannot exceed .

While is activated for the first time it generates an integer from the set . The next activating ends up in generating an integer from the set , which was not chosen before. If there is no such an integer, generates zero.

The machine starts with activating . Then the generators are activated according to the following rule: In case when a generator generated a positive integer , the next activated generator is . If zero is generated the machine stops.

The machine looses if the generator generates zero and the rest of the generators had exhausted their sets of integers. The machine is well constructed if it may generate a sequence of integers ending with zero, but not leading to a defeat.

Write a program that:

- reads from the standard input the description of the machine, i.e. the number of generators , integers and sets ,
- verifies, whether the machine described in the input file is well constructed,
- if it is well constructed, writes to the standard output a sequence of integers,
which may be generated by the machine, is ended with zero, and does not lead to defeat;
if not, writes one word
`NIE`(which means “no” in Polish).

In the first line of the standard input there is written one positive integer , . This is the number of generators. In the -st line (for ) there is written an integer followed by all the elements of the set (written in arbitrary order). The integers in each line are separated by single spaces.

In the standard output there should be written one word `NIE` (if the machine isn't well constructed)
or one line containing an appropriate finite series of integers separated by single spaces.

For the input data:

2 2 1 2 1 2

the correct result is:

2 2 0

whereas for the input data:

2 1 2 0

the correct output is:

NIE

*Task author: Wojciech Plandowski.*