P5757 [NOI2000] Mystery of the Ancient City
Description
The famous archaeologist Professor Shi discovered an ancient city ruin on the Yunmeng Plateau. To his delight, in this city that he called Ice-Peak City, there were $12$ huge stone tablets, engraved with information written in some kind of script, which he named the Ice-Peak script. However, when Professor Shi tried to find Ice-Peak City again, he failed again and again.
Fortunately, he had photographed all the text on the tablets. In order to uncover the secrets of Ice-Peak City, Professor Shi and his assistant Dr. Niu began to study the Ice-Peak script. They found that the Ice-Peak script has only one sentence type: declarative sentences, and only three categories of words: nouns (n), verbs (v), and auxiliary words (a). Its grammar is very simple:

After studying a large amount of material, they summarized an Ice-Peak dictionary. Since the Ice-Peak script happens to have $26$ letters, for convenience they use the letters $a$ to $z$ to represent them.
In the Ice-Peak script, there are no separators between sentences, nor between words. So splitting words and sentences is very troublesome for Professor Shi and Dr. Niu. They decided to use a computer to help solve this problem. Suppose you accept this job. Your first task is to write a program that splits an Ice-Peak article into the minimum number of sentences, and under this premise, splits the article into the minimum number of words.
Input Format
- Line $1$ contains the number of words in the dictionary $n$ ($n \le 1000$).
- Lines $2$ to $(n+1)$ each describe one word, in the form $"α.mot"$. Here $α$ is the part of speech, which can be one of n (noun), v (verb), a (auxiliary word), and $mot$ is the word. The word length does not exceed $20$. Words with the same spelling but different parts of speech are considered different words. For example, n.kick and v.kick in the sample input are two different words.
- Line $(n+2)$ of the input file is the article to be split, ending with ".".
- The article in the input file is guaranteed to be in the Ice-Peak script. The article consists of finitely many sentences, and each sentence contains only finitely many words. The article length does not exceed 5 KB.
Output Format
- Output two lines, each containing one integer.
- Line $1$ is the number of sentences after splitting.
- Line $2$ is the number of words after splitting.
Explanation/Hint
**Sample Explanation**
(For easier reading, the split words are separated by spaces, the part of speech is marked at the upper right of each word, one sentence per line, and a period indicates the end of a sentence.)
The output corresponds to the following splitting:
$ sillysnoopy^n \quad isnot^v \quad big^a \quad table^n. \\
baleine^n \quad kick^v \quad snoopy^n \quad silly^a \quad cry^v. $
If the following splitting is used:
$ silly^a \quad snoopy^n \quad isnot^v \quad big^a \quad table^n. \\
baleine^n \quad kick^v \quad snoopy^n \quad silly^a \quad cry^v.$
then the number of sentences is still $2$, but the number of words increases by $1$ to $10$. Clearly, the former splitting should be chosen rather than the latter.
Translated by ChatGPT 5