#include<bits/stdc++.h>
using namespace std;
int n,ans;
map<string,string> a;
int main(){
cin>>n;
n++;
while(n--){
string s;
getline(cin,s);
if(s[6]==' '){
string tm="";
int i=7;
for(i=7;s[i]!='(';i++){
tm+=s[i];
}
if(s[i+1]=='"'){
string tmp="";
for(int j=i+2;s[j]!='"';j++){
tmp+=s[j];
}
a[tm]=tmp;
ans+=tmp.size();
}else{
string tmp="";
for(int j=i+1;s[j]!=')';j++){
tmp+=s[j];
}
a[tm]=a[tmp];
ans+=a[tmp].size();
}
}else{
string tm="";
int i=12;
for(i=12;s[i]!='(';i++){
tm+=s[i];
}
if(s[i+1]=='"'){
string tmp="";
for(int j=i+2;s[j]!='"';j++){
tmp+=s[j];
}
a[tm]=tmp;
}else{
string tmp="";
for(int j=i+1;s[j]!=')';j++){
tmp+=s[j];
}
a[tm]=a[tmp];
}
}
}
cout<<ans;
return 0;
}