Tianjin University Online Judge
ProblemsSubmitRuns StatusRank ListStatisticsClarifications

C.   Course

Time Limit: 1.0 Seconds   Memory Limit: 65536K
Total Runs: 56   Accepted Runs: 17



There are N students and M courses in the school, but the students can't select their favorite courses freely. Because there is a strange rule: all the students must select the same number of courses. And what's more, each course can accept K students at most.

The students are all hard-working. They want to select as many courses as possible. Can you help them?

Input

The input contains several test cases. The first line of each test case contains three integers, N, M and K. Then N lines follow. For each line, the first number Ai indicating the amount of courses which the ith student likes. Then Ai integers follow, indicating his favorite courses.

Input is terminated with N = M = K = 0.

You can assume 1 ≤ N, M, K ≤ 50. All the courses are numbered from 1 to M.

Output

Output one line for each test case, indicating the maximum number of courses each student can select.

Sample Input

2 2 2
1 1
2 1 2
2 2 1
1 1
1 1
0 0 0

Sample Output

1
0

Problem Setter: RoBa



Source:  Tianjin Metropolitan Collegiate Programming Contest 2007

Problem ID in problemset: 2842



Submit   Back   Runs   Statistics   Clarifications

Tianjin University Online Judge v1.2.4