http://codeforces.com/problemset/problem/5/A
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int l = 0;
int c = 0;
String s;
while (in.hasNextLine()) {
s = in.nextLine();
if (s.charAt(0) == '+')
c++;//不要用set,因为有可能重名
else if (s.charAt(0) == '-')
c--;
else {
l += c*(s.length() - s.indexOf(':') - 1);
}
}
System.out.println(l);
}
}