#include<cstdio>
#include<iostream>
using namespace std;
int main(){
string a[100];
int temp=0,ans=0;
string b;
for(int i=0;i<100;i++){
while(scanf("%s",&a[i])!=EOF){
if(a[i][0]=='+'){
temp++;
}else if(a[i][0]=='-'){
temp--;
}else{
for(int j=0;j<a[i].size();j++){
if(j==':'){
ans=(ans+a[i].size()-j-1)*temp;
}
}
}
}
}
printf("%d",ans);
return 0;
}
求大佬指点