Girls' Celebration#2053

Girls' Celebration

10 segundos
64 megabytes
Muy difícil (≈2050)

In order to celebrate the -th anniversary of Tsinghua University, girls are planning to hold a party. They are experts at singing and dancing, and they love to perform in groups. In their current plan, there will be a stage and a row of seats. When a group of girls needs to sing or dance on the stage, they stand up from their seats and go to the stage. After performing, they return to their own seats (they do not exchange seats, because every girl has many personal belongings on her seat).

They want this procedure to look cool, so for each performance, the actresses' seats should be consecutive. For example, if there are girls and a performance is done by girls , , and , then they cannot sit in the order ---, since when girls , , and stand up, it is strange to see a non-actress (girl ) sitting between girls and .

As mentioned, they are very good at singing and dancing, so they managed to come up with many combinations. Now they are a bit worried: is there a way to seat all the girls so that the above requirement is satisfied (i.e., for every combination, the actresses' seats are consecutive)?

As a decent programmer, you decide (actually, you are asked) to write a program that can calculate the number of seating arrangements. Since the girls are constantly thinking about new combinations, your program should read new combinations and adjust the answer accordingly. When there are only a few possible arrangements (i.e., at most feasible solutions), your program should output all of them.

Entrada

There are several test cases. The first line contains three integers , , (1 \le n, m, k \le 200), where is the number of girls, is the number of combinations, and is the parameter described above. Each of the next lines contains a set of integers, terminated by a zero. These integers are the IDs of the girls in the combination (girls are numbered to ). The input is terminated by end-of-file (EOF). The size of the input file does not exceed MB.

Salida

For each new combination, output the number of seating arrangements after considering this combination. If there is no way, print 0 and ignore the combination. If there are at most ways, print them one per line, in lexicographical order.

Ejemplos

Ejemplo 1

Loading
Loading