+adabacaba
-adabacaba
+aca
aca:caba
-aca
+bacaba
-bacaba
+aba
-aba
+bad
 +cab
+abac
-abac
+baca
 +8UjgAJ
8UjgAJ:02hR7UBc1tqqfL
-8UjgAJ
+zdi
-zdi
 +acabadab
+caba0aba
 +Dmitry
+Mike
Dmitry:All letters will be used
Dmitry:qwertyuiopasdfghjklzxcvbnm QWERTYUIOPASDFGHJKLZXCVBNM
Dmitry:And digits too
Dmitry:1234567890 0987654321
-Dmitry
 +Dmitry
+Mike
+Kate
Dmitry:
 +badabac
badabac:abacabad
-badabac
+0ab
-0ab
+dabacab
-dabacab
+a0ab
-a0ab
+0abaca
-0abaca
+dabac
-dabac
+abaca
-abaca
+bacabada
-bacabada
+aca
-aca
+abadabaca
-abadabaca
+acaba
-acaba
+abacabadab
-abacabadab
 +qlHEc2AuYy
qlHEc2AuYy:YYRwD0 edNZgpE nGfOguRWnMYpTpGUVM aXDKGXo1Gv1tHL9
qlHEc2AuYy:yvh3GsPcImqrvoUcBNQcP6ezwpU0 xAVltaKZp94VKiNao
qlHEc2AuYy:zuCO6Opey L  eu7lTwysaSk00zjpv zrDfbt8l  hpHfu
+pErDMxgVgh
qlHEc2AuYy:I1FLis  mmQbZtd8Ui7y 1vcax6yZBMhVRdD6Ahlq7MNCw
qlHEc2AuYy:lz MFUNJZhlqBYckHUDlNhLiEkmecRh1o0t7alXBvCRVEFVx
pErDMxgVgh:jCyMbu1dkuEj5TzbBOjyUhpfC50cL8R900Je3R KxRgAI dT
qlHEc2AuYy:62b47eabo2hf vSUD7KioN ZHki6WB6gh3u GKv5rgwyfF
pErDMxgVgh:zD5 9 ympl4wR gy7a7eAGAn5xVdGP9FbL6hRCZAR6O4pT6zb
 +6JPKkgXDrA
+j6JHjv70An
+QGtsceK0zJ
6JPKkgXDrA:o4
+CSmwi9zDra
QGtsceK0zJ:Zl
QGtsceK0zJ:0
j6JHjv70An:7
j6JHjv70An:B
QGtsceK0zJ:OO
 +Dmitry
Dmitry:No phrases with spaces at the beginning and at the end
+Mike
Dmitry:spaces    spaces
-Dmitry
 +1aLNq9S7uLV
-1aLNq9S7uLV
+O9ykq3xDJv
-O9ykq3xDJv
+54Yq1xJq14F
+0zJ5Vo0RDZ
-54Yq1xJq14F
-0zJ5Vo0RDZ
+lxlH7sdolyL
-lxlH7sdolyL
 +adabacaba0
 +dabaca
-dabaca
+aba0ab
 +XqD
+aT537
XqD:x6ZPjMR1DDKG2
XqD:lLCriywPnB
-XqD
 +cabadabac
-cabadabac
+abacaba1ab
-abacaba1ab
+ba0abaca
 +acabadab
-acabadab
+aba0abacab
+baca
+abacaba0ab
-baca
-abacaba0ab
-aba0abacab
+cab
-cab
+abacabada
-abacabada
+badabaca
-badabaca
+badaba

4
 0
 14
 0
 224
 0
 8
 615
 34
 86
 0
 0
 0
 46
 0
 0

import java.util.Scanner;


public class main{
	public static int insert(String user, String[] users)
	{
		String user1 = user;
		String [] users1 = users;
		int trues = check(user1,users1);
		if(trues == 1)
		{
			return 0;	
		}
		else
		{
			for(int counter=0, continuer=1; counter<100 && continuer==1; counter++)
			{
				if(users1[counter]==null)
				{
					users[counter]=user1;
					continuer=0;
					return 1;
				}
			}
			return 0;
		}

	}
	public static void remove(String user, String[] users)
	{
		String user2 = user;
		String [] users2 = users;
		int trues = check(user2,users2);
		if(trues == 1)
		{
			for(int counter=0 ,continuer=1; counter<100 && continuer==1; counter++)
			{
				if(users2[counter].equals(user2))
				{
					users2[counter]=null;
					continuer=0;
				}
			}
		}else{
		}
	}
	public static int users(String[] users)
	{
		int count=0;
		for(int counter=0; counter<100;counter++)
		{
			if(users[counter] != null)
			{
				count++;
			}
		}
		return count;
	}
	public static int check(String user, String[] users)
	{
		if(user.isEmpty())
		{
			return 2;
		}
		else
		{
			for(int counter=0; counter<100; counter++)
			{
				if(user.equals(users[counter]))
				{
					return 1;
				}
			
			}
			return 0;
		}
	}
	public static int message(String user, String message)
	{
		int messageSize=0;
		if(message.charAt(0)==' ' || message.charAt(message.length()-1)==' ')
		{
			return 0;
		}
		else
		{
		for(int counter=0; counter < message.length(); counter++)
		{
			if(Character.isUpperCase(message.charAt(counter)))
			{
				messageSize+=2;
			}
			else
			{
				messageSize++;
			}
		}
		return messageSize;
	}
}
public static void main(String []args)
	{
		Scanner input = new Scanner(System.in);
		String [] users = new String[100];
		int result=0;
		int position=-1;
		int checkIsTrue=0;
		String userName;
		String command;
		int commandSize;
		int messageSize;
		String messageString;
		int userQuantity =0;

		for(int counter = 0; counter < 100; counter++)
		{
			command = input.nextLine();
			if(!input.hasNext()){
				break;
			}
			if(command.length()==100)
			{

			}
			else
			{
			if(command.charAt(0)=='+')
			{				
				//aqui entra o inserir
				insert(command.substring(1), users); 
			}
			else if(command.charAt(0)=='-')
			{
				//aqui entra o remover
				remove(command.substring(1), users);
			}
			else
			{
				position=command.indexOf(":");
				userName=command.substring(0, position);
				if(position==-1)
				{

				}
				else
				{
				checkIsTrue = check(userName,users);
				if(checkIsTrue==2)
				{

				}else if(checkIsTrue==0)
				{

				}
				else if(checkIsTrue==1)
				{	
					messageSize=0;
					commandSize=command.length();
					position++;
					messageString = command.substring(position, commandSize);
					//System.out.println(messageString);
					messageSize = message(userName, messageString);
					userQuantity = users(users);
					result = result +(messageSize*userQuantity);
				}
				}
				
				//aqui entra o checador se o usuario existe
			}
			}
		//System.out.println(result);
		}
		System.out.println(result);
	}
	//answer is the length of the messages and the number of users
}	
// 1520164189451
