Bob is a skilled system engineer who regularly faces challenging problems. He must now solve a new problem: manage a set of servers with various capabilities to process persistent job requests from continuous sources, where each job needs processing over a long or indefinite period.
A sequence of job requests arrives, each specifying a subset of servers capable of processing that job. Each job is processed on a single server, and each server can only process one job. Bob must schedule the maximum possible number of jobs on the servers. For example, if there are jobs j_1 and j_2, and servers s_1 and s_2, and both jobs j_1 and j_2 require server s_1, Bob can schedule only one job. Can you help him?
In the general case, there are jobs numbered from to n-1, servers numbered from to 2n-1, and a sequence of job requests. The task is to find the maximum number of jobs that can be processed.
The program reads input from a text file (at most MB). Each data set in the file represents a particular set of jobs. A data set starts with the number (n \leq 10000) of jobs, followed by the list of required servers for each job in the format: job_number: (nr_servers) s_1 ...s_{nr\_servers}
White spaces may appear freely in the input. The input data is correct and ends with the end of file.
The program outputs the maximum number of jobs that can be processed. For each data set, the program outputs the result to the standard output starting from the beginning of a line.
Example 1
A sample input/output is shown in the table below. There are two data sets. In the first case, the number of jobs is , numbered and . The sequence of requests for job is: 0: (1) 2, meaning that job requires server, namely server . The sequence of requests for job is: 1: (1) 2, meaning that job also requires server, server . The result for this data set is the maximum number of scheduled jobs, .