Problem AA
Transportation Delegation
You have just been hired by Amalgamated, Inc. in the country of Acmania to oversee the transportation of raw materials to the company’s factories. Each supplier of raw materials and each factory resides in one of Acmania’s states. No state has both a factory and a supplier (and never more than one of either) and there are arcane laws governing which transportation companies can transport materials across state lines. Because of the fierce competition between factories and between suppliers each transportation company handles the output of at most one raw material site and delivers to at most one factory (or to another transportation company). Each supplier can produce enough material to contract with at most one factory and no factory will contract with more than one supplier. Your job is to determine the maximum number of factories that can be supplied with raw materials.
For example, suppose that there are three suppliers in
states A, B and C, and three factories in states D, E and F.
Let’s say you contract three transportation firms: firm
Input
The input will start with four positive integers
Next will follow a line containing
The next line will contain
Finally there will be
All state names will be alphabetic strings with no
blanks.
Output
Output the maximum number of factories that can be supplied with raw materials.
Sample Input 1 | Sample Output 1 |
---|---|
7 3 3 3 A B C D E F 3 A E G 3 A C E 3 B D F |
2 |
Sample Input 2 | Sample Output 2 |
---|---|
7 3 3 4 A B C D E F 3 A E G 3 A C E 3 B D F 2 G F |
3 |