P1184 Being Together with the Expert
Background
An expert can be resurrected; we all know that.
Description
The expert has drawn up a detailed schedule. This time, he wants to pursue a pure-hearted little girl. Both he and she have classes, but there will also be free time, so the expert decides to follow her at all times. For her, the expert decides to transfer to first grade.
Now the expert has spent a lot of money to buy her schedule, which shows where she will be each day. A list of places convenient for the expert to go is also provided. He can visit convenient places any number of times, while inconvenient places cannot be visited.
There are $n$ convenient places to go and $m$ days. The expert wants to know the maximum number of days, within these $m$ days, that he can be together with her. Inconvenient places are not listed.
Input Format
The first line contains two integers $n, m$.
Then follow $n$ lines, each with the name of a place that is convenient for the expert to go.
Then follow $m$ lines, each with the name of the place where she is on that day.
**Place names may contain spaces.**
Output Format
An integer: the number of days they are at the same place.
Explanation/Hint
$1 \leq m \leq 10^6$, $1 \leq n \leq 20$.
Translated by ChatGPT 5