func_code_string: #include <bits/stdc++.h>   using namespace std;   const int MAXN = 100010;   int m, n, nword, R[MAXN], len[MAXN];   map<string, int> M;   string s[MAXN];   vector<int> adj[MAXN], adj2[MAXN];   int super[MAXN], nsuper, number[MAXN], low[MAXN], cnt;   int best[MAXN], rep[MAXN];   bool inStack[MAXN];   int st[MAXN], nst;   int f[MAXN];   long long resR, resLen;   void toLower(string& s) {     for (int i = 0; i < s.size(); i++) {       s[i] = tolower(s[i]);     }   }   int countR(string s) {     int ret = 0;     for (int i = 0; i < s.size(); i++) {       ret += s[i] ==  r ;     }     return ret;   }   void add(string& s) {     toLower(s);     if (M[s] == 0) M[s] = ++nword;     int x = M[s];     len[x] = s.length();     R[x] = countR(s);   }   void input() {     scanf( %d , &m);     for (int i = 1; i <= m; i++) {       cin >> s[i];       add(s[i]);     }     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       string tmp;       int u, v;       cin >> tmp;       add(tmp);       u = M[tmp];       cin >> tmp;       add(tmp);       v = M[tmp];       adj[u].push_back(v);     }   }   void tarjan(int u) {     number[u] = ++cnt;     low[u] = number[u];     inStack[u] = true;     st[++nst] = u;     for (int i = 0; i < adj[u].size(); i++) {       int v = adj[u][i];       if (number[v] == 0) {         tarjan(v);         low[u] = min(low[u], low[v]);       } else if (inStack[v])         low[u] = min(low[u], number[v]);     }     if (low[u] == number[u]) {       nsuper++;       best[nsuper] = u;       super[u] = nsuper;       inStack[u] = false;       while (st[nst] != u) {         int v = st[nst--];         super[v] = nsuper;         inStack[v] = false;         if (R[v] < R[best[nsuper]] ||             (R[v] == R[best[nsuper]] && len[v] < len[best[nsuper]]))           best[nsuper] = v;       }       nst--;     }   }   void dfs(int u) {     f[u] = best[u];     for (int i = 0; i < adj2[u].size(); i++) {       int v = adj2[u][i];       if (f[v] == 0) dfs(v);       if (R[f[v]] < R[f[u]] || (R[f[v]] == R[f[u]] && len[f[v]] < len[f[u]]))         f[u] = f[v];     }   }   void solve() {     for (int i = 1; i <= nword; i++) {       if (number[i] == 0) tarjan(i);     }     for (int i = 1; i <= nword; i++) {       for (int j = 0; j < adj[i].size(); j++) {         int v = adj[i][j];         if (super[i] != super[v]) adj2[super[i]].push_back(super[v]);       }     }     for (int i = 1; i <= nword; i++) {       if (f[i] == 0) dfs(i);     }     for (int i = 1; i <= m; i++) {       int id = M[s[i]];       resR += R[f[super[id]]];       resLen += len[f[super[id]]];     }   }   void output() { printf( %I64d %I64d , resR, resLen); }   int main() {     input();     solve();     output();   }   