感谢大佬
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <map>
using namespace std;
const int MAXL = 1e4+10;
map<string,string> user;
map<string,int> num;
int main(){
//freopen("test.in","r",stdin);
//freopen("test.out","w",stdout);
int l,cnt = 0;
scanf("%d",&l);
for(int i = 1; i <= l; i++){
char s[MAXL],s1[15],s2[MAXL];
char ch;
bool v = 1;
while((ch=getchar()) != ' ') if(ch == '_') v = 0;
scanf("%s",s);
int name_len,len = strlen(s),user_len = 0;
for(name_len = 0; s[name_len] != '('; name_len++){
s1[name_len] = s[name_len];
}
bool m = 1;
for(int j = name_len+2; j < len-2; j++){
if(s[j]!='"'){
s2[user_len] = s[j];
user_len++;
}
if(s[j] == '"') m = 0;
}
if(m) user[s1] = user[s2];
else {
user[s1] = s2;
num[s2] = user_len;
}
if(v) cnt += num[user[s1]];
}
printf("%d",cnt);
return 0;
}