시간 제한 메모리 제한 제출 정답 맞은 사람 정답 비율
1 초 128 MB 0 0 0 0.000%

문제

A gambling machine consists of n generators of integers: G1, ..., Gn, where 1 ≤ n ≤ 1,000. The generator Gi can generate integers only from the certain set Si ⊆ {1, ..., n}, or 0 which means that the game is over. The Si can be an empty set. Let ki be the number of elements of the set Si. The sum of all the integers ki, for i = 1, ..., n, cannot exceed 12,000.

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

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

The machine looses if the generator Gn 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 n, integers ki and sets Si,
  • 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 n, n ≤ 1,000. This is the number of generators. In the (i+1)-st line (for i = 1, ..., n) there is written an integer ki followed by all the elements of the set Si (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.

예제 입력 1

2
2 1 2
1 2

예제 출력 1

2 2 0