测评会员优惠活动进行中 · 开通 VIP,有效期内测评不限次 VIP 优惠中 · 测评不限次 立即查看

A9613. Fedor and Essay

编程题 普及/提高-

题目描述

After you had helped Fedor to find friends in the «Call of Soldiers 3» game, he stopped studying completely. Today, the English teacher told him to prepare an essay. Fedor didn't want to prepare the essay, so he asked Alex for help. Alex came to help and wrote the essay for Fedor. But Fedor didn't like the essay at all. Now Fedor is going to change the essay using the synonym dictionary of the English language.

Fedor does not want to change the meaning of the essay. So the only change he would do: change a word from essay to one of its synonyms, basing on a replacement rule from the dictionary. Fedor may perform this operation any number of times.

As a result, Fedor wants to get an essay which contains as little letters «R» (the case doesn't matter) as possible. If there are multiple essays with minimum number of «R»s he wants to get the one with minimum length (length of essay is the sum of the lengths of all the words in it). Help Fedor get the required essay.

Please note that in this problem the case of letters doesn't matter. For example, if the synonym dictionary says that word cat can be replaced with word DOG, then it is allowed to replace the word Cat with the word doG.

输入格式

The first line contains a single integer $m$ $(1<=m<=10^{5})$ — the number of words in the initial essay. The second line contains words of the essay. The words are separated by a single space. It is guaranteed that the total length of the words won't exceed $10^{5}$ characters.

The next line contains a single integer $n$ $(0<=n<=10^{5})$ — the number of pairs of words in synonym dictionary. The $i$ -th of the next $n$ lines contains two space-separated non-empty words $x_{i}$ and $y_{i}$ . They mean that word $x_{i}$ can be replaced with word $y_{i}$ (but not vise versa). It is guaranteed that the total length of all pairs of synonyms doesn't exceed $5·10^{5}$ characters.

All the words at input can only consist of uppercase and lowercase letters of the English alphabet.

输出格式

Print two integers — the minimum number of letters «R» in an optimal essay and the minimum length of an optimal essay.

输入输出样例

输入 #1
3
AbRb r Zz
4
xR abRb
aA xr
zz Z
xr y
输出 #1
2 6
输入 #2
2
RuruRu fedya
1
ruruRU fedor
输出 #2
1 10
上一题 去做题 下一题