Assigning Work with Penalty Points

No attempts yetTime limit3sMemory limit256 MB

Problem

Kangho's company has NN employees and MM jobs to finish. Employees are numbered 1 to NN, and jobs are numbered 1 to MM.

Each employee has a fixed list of jobs they can do. Every job is handled by exactly one person, and an employee normally takes only one job from that list. An employee who received XX penalty points last month takes at most X+1X+1 jobs.

Suppose there are three employees, and last month Minho (employee 1) received 2 points, Jaepil (employee 2) received 1 point, and Juhyun (employee 3) received 0 points. Then Minho takes at most 3 jobs, Jaepil at most 2 jobs, and Juhyun at most 1 job.

No employee knows their own score. Only KK, the sum of the penalty points over all employees, is known. Kangho uses that: he splits the KK points among the employees however he likes, so that as many jobs as possible get done. The points given to one employee form a non-negative integer, and the points sum to exactly KK.

For example, employee 1 can do jobs 1, 2, 3, 4, 5, employees 2, 3, and 4 can do only job 1, and employee 5 can do jobs 1 and 5. With K=2K = 2, giving 1 point to employee 1 and 1 point to employee 5 gets four jobs done. Giving both points to employee 1 instead lets employee 1 take three jobs, so employee 1 takes jobs 2, 3, 4, employee 2 takes job 1, and employee 5 takes job 5, which finishes all five.

Given the job list of every employee and the penalty sum KK, write a program that finds how many of the MM jobs can be done at most.

Input

The first line contains the number of employees NN, the number of jobs MM, and the penalty sum KK, separated by spaces. (1N,M10001 \le N, M \le 1000, 1KN1 \le K \le N)

Each of the next NN lines describes one employee. Line ii contains the number of jobs employee ii can do, followed by those job numbers, separated by spaces. The count is between 0 and MM, and no number appears twice on the same line.

Output

Print the largest number of jobs Kangho's company can finish.