+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.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Scanner;


 
public class Main {

	
	class Node{
		int value, nuOfC=0, done=0;
		List<Integer> connections;
		
		public Node(){
			connections = new ArrayList<Integer>();
		}

		public int getValue() {
			return value;
		}

		public void setValue(int value) {
			this.value = value;
		}

		public int getNuOfC() {
			return nuOfC;
		}

		public void setNuOfC(int nuOfC) {
			this.nuOfC = nuOfC;
		}

		public List<Integer> getConnections() {
			return connections;
		}

		public void setConnections(List<Integer> connections) {
			this.connections = connections;
		}
		
	}
	
	
	class Net{
		HashMap <Integer, Node> map;
		
		public Net(){
			map = new HashMap <Integer, Node>(); 
		}
		
		public void addNode(int val){
			Node node= new Node();
			node.setValue(val);
			map.put(val, node);
		}

		public void editNode(int from, int to) {
			Node node = map.get(from);
			node.nuOfC++;
			node.connections.add(to);
			map.replace(from, node);
		}

		
		public int getMax() {
			int ret = 1;
			while (true){
				int max=-1111, idx = -1;
				for (int i = 0;i<=map.size();i++){
					if (map.containsKey(i) && map.get(i).nuOfC > max && map.get(i).done == 0){
						max = map.get(i).nuOfC;
						idx = i;
					}
				}
				System.out.println(idx);
				if (idx == -1)
					break;
				List<Integer> list = map.get(idx).connections;
				Node nn = map.get(idx);
				nn.done = 1;
				map.replace(idx, nn);
				for (int i = 0 ; i <  map.get(idx).nuOfC ; i++){
					ret*=2;
				}
				HashMap <Integer, Node> map1 = new HashMap <Integer, Node>();
				for (int i = 0 ; i < list.size() ; i++){
					Node nod = map.get(list.get(i));
					if (nod!=null && nod.done==0){
						nod.nuOfC--;
						map1.put(list.get(i), nod);
					}
				}
				map = map1;
			}
			return ret;
		}
	}
	
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		
		

		
		
		
	
	
		// 5A
	 	
	 	File file = new File("input.txt");
	 	Scanner im ;
	 	String h;
		int l = 0;
		int alive =0;
	 	try {
			im = new Scanner(new FileInputStream(file));
			while(im.hasNextLine()){
				h = im.nextLine();
				if (h.charAt(0) == '+'){
					alive++;
				}
				else if (h.charAt(0) == '-'){
					alive--;
				}else{
					int idx = h.indexOf(':');
					int msg = ((int)h.length()) - idx-1;
					l += (msg*alive);
				}
			}
			im.close();
			System.out.println(l);
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		}
	 	
	 
		
		
		/*
		// 445B
		int n = in.nextInt(), m = in.nextInt();
		int [] arr= new int[n+1];
		int ret = (int)Math.pow(2, n-1);
		for (int i = 1 ; i <=m ;i++){
			int e = in.nextInt(), g = in.nextInt();
			arr[e] = 1;
			arr[g] = 1;
		}
		int cou = 0;
		for (int i = 1 ; i <= n ; i++){
			if (arr[i] != 1)
				cou++;
		}
		for (int i = 0 ; i  < cou-1 ; i ++)
			ret/=2;
		
		System.out.println(ret);*/
		
		/*
		//245A
		int n = in.nextInt();
		int sa=0,sag=0,sb=0,sbg=0;
		for (int i = 0 ; i < n;i++){
			int t = in.nextInt(),x = in.nextInt(),y = in.nextInt();
			if (t==1){
				sa+=10;
				sag+=x;
			}
			if (t==2){
				sb+=10;
				sbg+=x;
			}
		}
		if (sag>=(sa/2))
			System.out.println("LIVE");
		else
			System.out.println("DEAD");
		if (sbg>=(sb/2))
			System.out.println("LIVE");
		else
			System.out.println("DEAD");
			*/

		
		
		
		/*		
		//         	
	    string n; int k;
	    cin >> n >> k;
	    
	    for (int i = 0 ; i < n.size()-1 ; i++){
			if (n[i] < n[i+1] && k>0){
				char h = n[i];
				n[i] = n[i+1];
				n[i+1] = h;
				k--;
				for (int j = i ; j > 0 ; j--){
					if (n[j] > n[j-1] && k>0){
						char h = n[j];
						n[j] = n[j-1];
						n[j-1] = h;
						k--;
					}
				}
			}
			if (k==0)
				break;
		}
	    cout << n;*/
		
/*		 // 584C
		int n= in.nextInt(), m= in.nextInt();
		String s1 = in.next(), s2 = in.next();
		int same = 0;
		for (int i = 0 ; i < n ; i++){
			if (s1.charAt(i) == s2.charAt(i)){
				same++;
			}
		}
		
		if (same <= m ){
			System.out.println(-1);
			System.exit(0);
		}
*/
		
/*
		int w = in.nextInt(), h = in.nextInt(), n = in.nextInt();
		
		int arrw[] = new int[200001];
		int arrh[] = new int[200001];
		arrw[0]=1;
		arrh[0]=1;
		for (int i = 0 ; i < 4 ; i++){
			String dir = in.next();
			int num = in.nextInt();
			
			
			
			System.out.println(dir+"           "+num);
			
			
			
			if (dir.equals("H")){
				arrw[num] = 1;
			}else{
				arrh[num] = 1;
			}
			
			
			int maxw=-1231233,maxh=-1212121;
			int id = -1,idx=-1;
			for (int p = 0 ; p < 200001;p++){
				if (arrw[p]==1){
					if (id !=-1){
						maxw = Math.max(maxw, p-id);
					}
					id = p;
				}
				if (arrh[p]==1){
					if (idx !=-1){
						maxh = Math.max(maxh,p-idx);
					}
					idx = p;
				}
			}

			
			
			System.out.println(maxh * maxw);
		}
		
*/
		
		
		
		
/*
		// 614/B
		int n ;
		n = in.nextInt();
		BigInteger z = new BigInteger("10");
		String h = "";String ret = "";
		for (int j = 0 ;j < n ; j++){
			h += in.next();
			h+= " ";
		}
		

		Scanner im = new Scanner(h);
		int ind= 0;
		while(im.hasNext()){
			BigInteger g = new BigInteger(im.next());
			
			BigInteger y =z.pow(g.toString().length()-1);
			if (g.subtract(y).compareTo( BigInteger.ZERO ) == 1){
				System.out.print(g);
				String q = g.toString();
				for (int o = q.length()-1 ; o >=0 ; o--){
					if (q.charAt(o) == '0'){
						ind++;
					}
					if (q.charAt(o) != '0'){
						break;
					} 
				}
				break;
			}
		}
		im.close();

		
		int ones = 1;
		for (int i = h.length()-1 ; i>=0 ; i--){
			
			if (h.charAt(i) != '0'){
				ones=0;
			}
			if (h.charAt(i) == ' '){
				ones = 1;
			}
			if (h.charAt(i) == '0' && ones == 1 && i !=0 && h.charAt(i-1) != ' '){
				ret+='0';
			}
			if ( (h.charAt(i) == '0' && ones == 1 && i == 0) ||  (h.charAt(i) == '0' && ones == 1 && i != 0 && h.charAt(i-1) == ' ') ){
				System.out.println(0);
				in.close();
				System.exit(0);
			}

		}
System.out.println(ret.substring(0,ret.length()-ind));
*/
		
		
		
		in.close();
	}


}
