Giorgio is working on a scientific paper involving Bayesian spam filtering, a statistical method used by mail providers to detect spam emails. This method can be very efficient in practice, but Giorgio wants to measure how much exactly. For this research, he will first implement a naive content-based filter. This filter compares each word in the email text against a set of “bad” words: if the email contains a bad word (e.g. dollars) then it’s likely to be spam. Moreover, the filter compares the words against another set, this time made of “good” words: if the email contains a good word (e.g. paper) then it’s likely to be a legitimate mail.
Help Giorgio count how many of his emails are likely spam and how many are likely legitimate. If an email is both likely spam and likely legitimate at the same time (or if Giorgio doesn’t have enough information to tell if it’s likely spam or likely legitimate) then it’s a dubious mail: it should not be counted at all.
Input data
The first line contains an integer , the number of bad words. The following line contains space-separated words (the bad ones). The following line contains an integer , the number of good words. The following line contains space-separated words (the good ones). The following line contains an integer , the number of emails in Giorgio’s inbox. Then emails follow: each email is represented by two consecutive lines, the first one contains an integer , the number of words in the -th email, the second one contains space-separated words (the email content).
Output data
You need to write a single line with two integers: the number of emails likely to be spam, and the number of emails likely to be legitimate.
Constraints and clarifications
- for each .
- Every word is between and characters long and contains only lowercase English letters.
# | Score | Constraints |
---|---|---|
1 | 5 | Examples |
2 | 25 | |
3 | 40 | |
4 | 30 | No additional limitations |
Example 1
stdin
3
dollars invest enlarge
4
scientific paper deadline
professor
3
6
hey giorgio send me the paper
8
now is the time to invest in
bitcoin
11
i wonder why we dont invest more
for the scientific advancement
stdout
1 1
Explanation
In the first sample case the last email is the only dubious one (invest, scientific). The first one is likely legitimate, the second is likely spam.
Example 2
stdin
1
yikes
1
yummy
5
2
yummy yummy
2
likes bikes
2
yummy bikes
2
yummy yikes
2
bikes yikes
stdout
1 2
Explanation
In the second sample case the last email is likely spam, while the first and third emails are likely legitimate.