cho.sh
Notes
Loading...

Task Order

Time limit

2s

Memory limit

128 MB

Problem

A process consists of N (1 <= N <= 1,000) tasks. To finish the process, every task must be performed exactly once.

All tasks are performed by one machine. After a task finishes, only certain tasks may be performed immediately next. Therefore, to process several tasks consecutively, their order must be entered into the machine before the work starts.

The machine performs the actual tasks very quickly, but entering a task order takes a very long time. Even entering an order containing just one task is considered expensive. Your goal is to perform every task exactly once while minimizing the number of times an order is entered.

The relation between tasks is not necessarily transitive. For example, even if task 2 can immediately follow task 1 and task 3 can immediately follow task 2, task 3 may not be able to immediately follow task 1. Conversely, even if task 3 cannot immediately follow task 1, the order 1 2 3 may still be valid. Only the relation between the task performed immediately before and the next task matters.

For every two different tasks A and B, at least one of the two directions is possible: B can immediately follow A, or A can immediately follow B. Both directions may also be possible.

Input

The first line contains the integer N.

Each of the next N lines contains N integers, each either 0 or 1. If the j-th integer on the i-th line is 1, then task j can be performed immediately after task i finishes.

Output

Print X, the minimum number of times a task order must be entered, on the first line.

Then print X lines, one for each entered order. The first integer Y on a line is the number of tasks in that order, followed by Y task numbers in the order they are performed.

Every task must appear exactly once across the whole output. If there are several optimal answers, print any one of them.

Hint

If the tasks can be entered once in the order 1 2 3, the task order only needs to be entered one time. Since no task remains afterward, the process ends there.