Inspection#529

Inspection

1 second
64 megabytes
Very hard

You are in charge of a team that inspects a new ski resort. A ski resort is situated on several mountains and consists of a number of slopes. Slopes are connected with each other, forking and joining. A map of the ski resort is represented as an acyclic directed graph. Nodes of the graph represent different points in the ski resort, and edges of the graph represent slopes between the points, with the direction of edges going downwards.

Your team has to inspect each slope of the ski resort. Ski lifts on this resort are not open yet, but you have a helicopter. In one flight, the helicopter can drop one person into any point of the resort. From the drop-off point, the person can ski down the slopes, inspecting each slope as they go. It is acceptable to inspect the same slope multiple times, but you must minimize the usage of the helicopter. Thus, you must determine how to inspect all the slopes with the fewest number of helicopter flights.

Input

The first line of the input file contains a single integer (2 \le n \le 100) — the number of points in the ski resort. The following lines of the input file describe each point of the ski resort numbered from to . Each line starts with a single integer m_i (0 \le m_i < n), followed by m_i integer numbers a_{ij} separated by spaces. All a_{ij} are distinct for each , and each a_{ij} (1 \le a_{ij} \le n, a_{ij} \ne i) represents a slope going downwards from point to point a_{ij}. Each point in the resort has at least one slope connected to it.

Output

On the first line of the output file, write a single integer — the minimal number of helicopter flights needed to inspect all slopes. Then write lines that describe inspection routes for each helicopter flight. Each route should start with a single integer from to — the number of the drop-off point for the helicopter flight, followed by the numbers of the points that will be visited in order as the slopes are inspected going downwards. Numbers on a line should be separated by spaces. You can write routes in any order.

Examples

Example 1

Loading
Loading