#C100. Mentoring Pairs Matching

    ID: 39156 Type: Default 1000ms 256MiB

Mentoring Pairs Matching

Mentoring Pairs Matching

You are given two sets of individuals: mentors and mentees. Each mentor has a set of programming languages they are proficient in, and each mentee has a set of programming languages they wish to learn. Your task is to determine the maximum number of mentoring pairs that can be formed such that for every paired mentor and mentee, there is at least one programming language common to both.

Each mentor and mentee can be paired at most once. The matching is done greedily by considering each mentee in order and assigning them the first available mentor that shares at least one common language.

Note: The input is provided via stdin and the output must be printed to stdout.

inputFormat

The input is given via stdin as follows:

M
mentor_1 language_1 language_2 ... language_k
mentor_2 language_1 language_2 ... language_k
... (M mentors in total)
N
mentee_1 language_1 language_2 ... language_p
mentee_2 language_1 language_2 ... language_p
... (N mentees in total)

Where M is the number of mentors and N is the number of mentees. Each mentor or mentee is described in one line, starting with their name followed by the programming languages separated by spaces.

outputFormat

Print a single integer representing the maximum number of mentoring pairs that can be formed based on the criteria described above.

## sample
3
Alice Python C++
Bob Java Python
Charlie JavaScript
3
Xander Python
Yara JavaScript Python
Zane C# Java
2

</p>