Science Against Spam

Time limit: 0.5s Memory limit: 64MB Input: Output:

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 BB, the number of bad words. The following line contains BB space-separated words (the bad ones). The following line contains an integer GG, the number of good words. The following line contains GG space-separated words (the good ones). The following line contains an integer EE, the number of emails in Giorgio’s inbox. Then EE emails follow: each email is represented by two consecutive lines, the first one contains an integer NiN_i, the number of words in the ii-th email, the second one contains NiN_i 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

  • 1B1 0001 \leq B \leq 1 \ 000
  • 1G1 0001 \leq G \leq 1 \ 000
  • 1E1 0001 \leq E \leq 1 \ 000
  • 1Ni1 0001 \leq N_i \leq 1 \ 000 for each i=0E1i = 0 \dots E − 1.
  • Every word is between 11 and 2020 characters long and contains only lowercase English letters.
# Score Constraints
1 5 Examples
2 25 Ni=1N_i = 1
3 40 B,G,E100B, G, E \leq 100
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.

Log in or sign up to be able to send submissions!