#include<bits/stdc++.h> using namespace std; string s; int t,ans; int main() { while(getline(cin,s)) { if(s[0]=='+') { t++; } else if(s[0]=='-') { t--; } else { int i=s.find(':'); ans=ans+t*(s.size()+1-i); } } cout<<ans<<endl; return 0; }