Archaeological Research

Given the surviving shuffled entries of a table of next occurrences for an unknown alphabet size, recover the lexicographically smallest original sequence or report that none exists.

Hard9GreedyGraphImplementationSortingNo attempts yetTime limit2sMemory limit512 MB

Problem

Professor Tupids dug up a new archaeological document during a recent survey.

The document is nn symbols long and uses an alphabet of cc symbols. To study its meaning the professor gave each symbol a natural number from 11 to cc, so the document can be written as a sequence of nn natural numbers between 11 and cc.

To examine the relations between the symbols the professor built a large table with nn rows and cc columns. The value written in row ii, column jj is the position of the first occurrence of symbol jj after position ii in the sequence. When no such position exists, the cell holds 00.

For example, take n=6n = 6, c=3c = 3 and the sequence [1,3,2,2,1,3][1, 3, 2, 2, 1, 3]. A few cells of the table are:

  • Row 33, column 22 holds 44, because the first symbol 22 after position 33 sits at position 44.
  • Row 22, column 33 holds 66, because the first symbol 33 after position 22 sits at position 66.
  • Row 55, column 11 holds 00, because symbol 11 never appears after position 55.

One day a fire broke out in the laboratory and the document burned away. The table was not lost completely, but it was damaged. The record of the value of cc is gone, some cells are no longer legible, and an assistant stored the table so badly that the numbers inside each row were shuffled.

The professor wants to recover the original document from what is left. Infinitely many sequences can fit, so the professor asks for the lexicographically smallest one. If the content of the table is wrong, no sequence fits at all, and then it is enough to bring the professor that sad news.

Read the damaged table and recover the original sequence.

Input

The first line holds the length nn (1n3000001 \le n \le 300000) of the original sequence.

Line ii of the next nn lines holds an integer cic_i (0cini0 \le c_i \le n - i) followed by cic_i natural numbers. These cic_i numbers are the numbers still legible in row ii of the table. They are at most nn and pairwise different, and the order they are written in can differ from the order in the original table.

The sum of all cic_i is at most 300000300000.

Output

If a sequence satisfies the table, print its nn numbers on one line, separated by single spaces. If several sequences satisfy the table, print the lexicographically smallest one.

If no sequence satisfies the table, print "No Solution".