A group of $N$ ($3 \le N \le 200$) cows is having a New Year's party. Each cow is able to cook several different kinds of food (in units called a "dish"). There are a total of $D$ ($5 \le D \le 100$) different kinds of food. Each kind of food is denoted by an integer in the range $1..D$.
The cowrdinator wants to maximize the total number of dishes brought to the party, but has specified a limit for the number of dishes of each type. Each cow can bring $K$ ($1 \le K \le 5$) dishes, but they must be different from each other (she can't bring 3 bovine pies, for example, but she could bring a pie, some bread, and some nice alfalfa in orange sauce). What is the maximum amount of food that can be brought?
Input
- Line $1$: Three integers: $N$, $K$, and $D$
- Line $2$: $D$ non-negative integers: the limit on total number of each of the various dishes that can be brought to the party
- Lines $3..N+2$: Each line contains an initial integer $Z$ ($1 \le Z \le D$) denoting the number of different dishes a cow can prepare; the rest of the line contains $Z$ integers that are the food identifiers, food type 1 first, food type 2 second, etc..
Output
A single line with a single integer that is the maximum number of dishes that can be brought to the party.
Examples
Input 1
4 3 5
2 2 2 2 3
4 1 2 3 4
4 2 3 4 5
3 1 2 4
3 1 2 3
Output 1
9
Input Details
data...... explanation...................................................
4 3 5 4 cows, each cow brings up to 3 dishes, 5 different food types
2 2 2 2 3 max for party of 2 dishes food types 1..4; 3 dishes of food 5
4 1 2 3 4 This cow can cook 4 different foods (1, 2, 3, 4)
4 2 3 4 5 This cow can cook 4 different foods (2, 3, 4, 5)
3 1 2 4 This cow can cook 3 different foods (1, 2, 4)
3 1 2 3 This cow can cook 3 different foods (1, 2, 3)
Output Details
[Cow 1 brings foods 3 and 4; cow 2 brings foods 3, 4 and 5; cow 3 brings foods 1 and 2; and cow 4 brings foods 1 and 2.]
Problem credits: Hal Burch, 2001