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 team of speleologists organizes a training in the Great Cave of Byte Mountains. During the training each speleologist explores a route from Top Chamber to Bottom Chamber. The speleologists may move down only, i.e. the level of every consecutive chamber on a route should be lower then the previous one. Moreover, each speleologist has to start from Top Chamber through a different corridor and each of them must enter Bottom Chamber using different corridor. The remaining corridors may be traversed by more then one speleologist. How many speleologists can train simultaneously?

Write a program which:

- reads the cave description from the standard input,
- computes the maximal number of speleologists that may train simultaneously,
- writes the result to the standard output.

In the first line of the standard input there is one integer (), equal to the number of chambers in the cave. The chambers are numbered with integers from to in descending level order - the chamber of greater number is at the higher level than the chamber of the lower one. (Top Chamber has number , and Bottom Chamber has number ). In the following lines (i.e. lines ) the descriptions of corridors are given. The -th line contains numbers of chambers connected by corridors with the -th chamber. (only chambers with numbers grater then are mentioned). The first number in a line, , , is a number of corridors exiting the chamber being described. Then the following integers are the numbers of the chambers the corridors are leading to.

Your program should write one integer in the only line of the standard output. This number should be equal to the maximal number of speleologists able to train simultaneously.

For the input data:

12 4 3 4 2 5 1 8 2 9 7 2 6 11 1 8 2 9 10 2 10 11 1 12 2 10 12 1 12 1 12

describing the following cave:

the correct result is:

3

*Task author: Marcin Kubica.*