Polycarp is working on a new project called "Polychat". Following modern tendencies in IT, he decided, that this project should contain chat as well. To achieve this goal, Polycarp has spent several hours in front of his laptop and implemented a chat server that can process three types of commands:

  * Include a person to the chat ('Add' command). 
  * Remove a person from the chat ('Remove' command). 
  * Send a message from a person to all people, who are currently in the chat, including the one, who sends the message ('Send' command). 



Now Polycarp wants to find out the amount of outgoing traffic that the server will produce while processing a particular set of commands.

Polycarp knows that chat server sends no traffic for 'Add' and 'Remove' commands. When 'Send' command is processed, server sends l bytes to each participant of the chat, where l is the length of the message.

As Polycarp has no time, he is asking for your help in solving this problem.

Input

Input file will contain not more than 100 commands, each in its own line. No line will exceed 100 characters. Formats of the commands will be the following:

  * +<name> for 'Add' command. 
  * -<name> for 'Remove' command. 
  * <sender_name>:<message_text> for 'Send' command. 



<name> and <sender_name> is a non-empty sequence of Latin letters and digits. <message_text> can contain letters, digits and spaces, but can't start or end with a space. <message_text> can be an empty line.

It is guaranteed, that input data are correct, i.e. there will be no 'Add' command if person with such a name is already in the chat, there will be no 'Remove' command if there is no person with such a name in the chat etc.

All names are case-sensitive.

Output

Print a single number — answer to the problem.

Examples

Input

+Mike
Mike:hello
+Kate
+Dmitry
-Dmitry
Kate:hi
-Kate


Output

9


Input

+Mike
-Mike
+Mike
Mike:Hi   I am here
-Mike
+Kate
-Kate


Output

14

Source: codeforces | Difficulty: EASY
Tags: Implementation


Solutions:
import sys
n = 0
ans = 0
while True:
	i = sys.stdin.readline().strip()
	if len(i) <= 1:
		break
	if i[0] == '+':
		n += 1
	elif i[0] == '-':
		n -= 1
	else:
		ans += len(i.split(':')[1]) * n
print(ans)


online = set()
answer = 0
try:
	while True:
		line = input()
		if line[0] == '+' or line[0] == '-':
			name = line[1:]
			if line[0] == '+':
				online.add(name)
			else:
				online.remove(name)
		else:
			answer += len(line.split(':')[1]) * len(online)
except:
	pass
print(answer)


c = 0
o = 0
while True:
	try:
		cmd = input()
		if cmd[0] == '+':
			c += 1
		elif cmd[0] == '-':
			c -= 1
		else:
			o += len(cmd.split(':')[1]) * c
	except:
		break
print(o)


import sys
ans = 0
st = set()
while sys.stdin:
	try:
		cmd = input()
		if cmd[0] == '+':
			st.add(cmd[1:])
		elif cmd[0] == '-':
			st.remove(cmd[1:])
		else:
			ans += len(st) * len(cmd.split(':')[1])
	except IndexError:
		break
	except EOFError:
		break
print(ans)


import sys

def solution():
	commands = sys.stdin.readlines()
	members = 0
	sent = 0
	for command in commands:
		if command.startswith('+'):
			members += 1
		elif command.startswith('-'):
			members -= 1
		else:
			message = command.split(':')[1].rstrip('\n')
			sent += len(message) * members
	print(sent)
solution()


import sys
p = res = 0
for x in sys.stdin:
	if x[0] == '+':
		p += 1
	elif x[0] == '-':
		p -= 1
	else:
		res += p * (len(x) - x.find(':') - 2)
print(res)


output = 0
num_members = 0
while True:
	try:
		k = input()
		if k[0] == '+':
			num_members += 1
		elif k[0] == '-':
			num_members -= 1
		else:
			lst = k.split(':')
			output += num_members * len(lst[1])
	except:
		break
print(output)


mates = 0
result = 0
while 1:
	try:
		inp = input()
		if inp.startswith('+'):
			mates += 1
		elif inp.startswith('-'):
			mates -= 1
		else:
			result += len(inp.split(':')[-1]) * mates
	except EOFError:
		break
print(result)


def main():
	bytecount = 0
	participants = []
	try:
		while True:
			line = input()
			if line[0] == '+':
				person = line[1:]
				participants.append(person)
			elif line[0] == '-':
				person = line[1:]
				participants.remove(person)
			elif ':' in line:
				(person, message) = line.split(':')
				bytecount += len(message) * len(participants)
	except EOFError:
		pass
	print(bytecount)
main()


d = []
score = 0
while True:
	try:
		line = input()
	except:
		print(score)
		break
	if line[0] == '+':
		s = line[1:]
		d.append(s)
	elif line[0] == '-':
		s = line[1:]
		d.remove(s)
	else:
		s = line.split(':')
		s = len(s[1])
		score += s * len(d)


import sys
participants = []
ans = 0
for s in sys.stdin:
	if not s.strip():
		break
	if s[0] == '+':
		participants.append(s[1:])
	elif s[0] == '-':
		participants.remove(s[1:])
	else:
		ans += (len(s) - s.find(':') - 2) * len(participants)
print(ans)


m = 0
mem = []
while 1:
	try:
		com = input()
	except:
		break
	if com[0] == '+':
		com = com.replace('+', '')
		mem.append(com)
	elif com[0] == '-':
		com = com.replace('-', '')
		mem.remove(com)
	elif ':' in com:
		com = com.split(':')[1]
		m = m + len(com) * len(mem)
print(m)


room = {}
traffic = 0
while 1:
	try:
		s = input()
	except EOFError:
		break
	if s[0] == '+':
		room[s[1:]] = None
	elif s[0] == '-':
		room.pop(s[1:])
	else:
		traffic += len(s.split(':')[1]) * len(room)
print(traffic)


import sys
(people, bits) = (0, 0)
for i in sys.stdin:
	if i[0] == '+':
		people += 1
	elif i[0] == '-':
		people -= 1
	else:
		bits += people * (len(i) - i.find(':') - 2)
print(bits)


import sys
n = 0
s = 0
for i in sys.stdin:
	if i[0] == '+':
		n += 1
	elif i[0] == '-':
		n -= 1
	else:
		s = s + n * (len(i.split(':')[1]) - 1)
print(s)


import sys
(users, ans) = (list(), 0)
for line in sys.stdin:
	line = line.rstrip()
	if line[0] == '+':
		users.append(line[1:])
	elif line[0] == '-':
		users.remove(line[1:])
	else:
		colonIndex = line.index(':')
		message = line[colonIndex + 1:]
		ans += len(message) * len(users)
print(ans)


from functools import reduce
from operator import *
from math import *
from sys import *
from string import *
from collections import *
setrecursionlimit(10 ** 7)
dX = [-1, 1, 0, 0, -1, 1, -1, 1]
dY = [0, 0, -1, 1, 1, -1, -1, 1]
RI = lambda : list(map(int, input().split()))
RS = lambda : input().rstrip().split()
s = 0
ans = 0
for l in stdin:
	l = l.rstrip()
	if l[0] == '+':
		s += 1
	elif l[0] == '-':
		s -= 1
	else:
		(t, l) = l.split(':')
		ans += s * len(l)
print(ans)


import sys
user = 0
text = 0
for message in sys.stdin:
	if message[0] == '+':
		user += 1
	elif message[0] == '-':
		user -= 1
	else:
		text += user * (len(message) - message.find(':') - 2)
print(text)


import sys
list = []
sum = 0
for reg in sys.stdin:
	a = 0
	if reg[0] == '+':
		list.append(reg[1:])
	elif reg[0] == '-':
		list.remove(reg[1:])
	else:
		a = len(reg) - reg.find(':') - 2
		sum += a * len(list)
print(sum)


ans = 0
active = 0
while True:
	try:
		s = input()
		if '+' in s:
			active += 1
		elif '-' in s:
			active -= 1
		else:
			x = s.split(':')[1]
			ans += len(x) * active
	except:
		print(ans)
		break


import sys
messages = []
for line in sys.stdin:
	messages.append(line.rstrip())
participants = 0
traffic = 0
for message in messages:
	if message.startswith('+'):
		participants += 1
	elif message.startswith('-'):
		participants -= 1
	else:
		text = message.split(':', 1)[1]
		traffic += len(text) * participants
print(traffic)


from sys import stdin as s
commands = s.readlines()
users = 0
traffic = 0
for c in commands:
	if c[0] == '+':
		users += 1
	elif c[0] == '-':
		users -= 1
	else:
		(name, message) = c.split(':')
		messageLength = len(message) - 1
		traffic += users * messageLength
print(traffic)


people_num = 0
result = 0
while True:
	try:
		src = input()
		if src[0] == '+':
			people_num += 1
		elif src[0] == '-':
			people_num -= 1
		else:
			num = len(src) - src.find(':') - 1
			result += people_num * num
	except:
		print(result)
		break


import sys
memb = 0
sum1 = 0
lst = []
for line in sys.stdin:
	line = line.strip('\n')
	if line == '':
		break
	if line[0] == '+':
		memb += 1
	elif line[0] == '-':
		memb -= 1
	else:
		lst = line.split(':')
		sum1 += len(lst[1]) * memb
print(sum1)


import sys
k = 0
q = 0
for line in sys.stdin:
	if ':' in line:
		q += (len(line[line.find(':'):]) - 2) * k
	elif '+' in line:
		k += 1
	elif '-' in line:
		k -= 1
print(q)


from sys import stdin

def ifAdd(name, members):
	members.append(name.replace('+', ''))

def ifRemove(name, members):
	members.remove(name.replace('-', ''))

def countTraffic(line, members):
	delete = line.find(':')
	line = line[delete + 1:]
	return (len(line) - 1) * len(members)

def getFileData():
	members = []
	traffic = 0
	for line in stdin:
		if line[0] == '+':
			ifAdd(line, members)
		elif line[0] == '-':
			ifRemove(line, members)
		else:
			traffic += countTraffic(line, members)
	print(traffic)
getFileData()


name = []
ans = 0
while 1:
	try:
		s = input()
		if s[0] == '+':
			name.append(s[1:])
		elif s[0] == '-':
			name.remove(s[1:])
		else:
			tmp = s.split(':')
			ans += len(tmp[1]) * len(name)
	except:
		break
print(ans)


import sys
people = 0
total = 0
for i in sys.stdin:
	if i[0] == '+':
		people += 1
	elif i[0] == '-':
		people -= 1
	else:
		total += people * (len(i) - i.index(':') - 2)
print(total)


a = 0
c = 0
while True:
	try:
		x = input()
	except:
		break
	if x[0] == '+':
		a = a + 1
	elif x[0] == '-':
		a = a - 1
	elif x.find(':') != -1:
		i = x.find(':')
		c = c + len(x[i + 1:]) * a
print(c)


import sys
ADD = '+'
REMOVE = '-'
SEND = ':'
(chatters, answer) = (0, 0)
for command in sys.stdin:
	if command[0] == ADD:
		chatters += 1
	elif command[0] == REMOVE:
		chatters -= 1
	else:
		(name, message) = command.split(SEND)
		answer += chatters * len(message.strip())
print(answer)


import sys
bt = 0
num = 0
for line in sys.stdin:
	if line[0] == '+':
		num += 1
	elif line[0] == '-':
		num -= 1
	else:
		bt += num * (len(line) - line.index(':') - 2)
print(bt)


(c, n) = (0, 0)
while True:
	try:
		s = input()
		if s[0] == '+':
			n += 1
		elif s[0] == '-':
			n -= 1
		elif s[0] not in '+-':
			z = s.index(':')
			s = s[z + 1:]
			c += n * len(s)
	except:
		break
print(c)


import sys
l = list(map(lambda x: x.strip(), sys.stdin.readlines()))
mem_count = 0
b_count = 0
for ll in l:
	if ll.startswith('+'):
		mem_count += 1
	elif ll.startswith('-'):
		mem_count -= 1
	else:
		(name, m) = ll.split(':')
		b_count += len(m) * mem_count
print(b_count)


def main():
	l = []
	while True:
		try:
			l.append(input())
		except Exception as e:
			break
	s = set()
	r = 0
	for line in l:
		if line[0] == '+':
			s.add(line[1:])
		elif line[0] == '-':
			s.remove(line[1:])
		else:
			r += len(s) * len(line.split(':')[1])
	return r
print(main())


class Chat:

	def __init__(self):
		self.users = []
		self.bytes_sent = 0

	def add_user(self, name):
		self.users.append(name)

	def remove_user(self, name):
		self.users.pop(self.users.index(name))

	def send_msg(self, msg):
		self.bytes_sent += len(msg) * len(self.users)

	def process_cmd(self, cmd):
		if '+' in cmd:
			self.add_user(cmd.split('+')[1])
		elif '-' in cmd:
			self.remove_user(cmd.split('-')[1])
		else:
			self.send_msg(cmd.split(':')[1])
chat = Chat()
while True:
	try:
		chat.process_cmd(input())
	except:
		break
print(chat.bytes_sent)


d = set()
count = 0
try:
	while 1:
		s = input()
		if s.startswith('+'):
			d.add(s[1:])
		elif s.startswith('-'):
			d.remove(s[1:])
		else:
			count += len(s.split(':')[-1]) * len(d)
except:
	pass
print(count)


n = input()
cnt = 0
ans = 0
while True:
	if n[0] == '+':
		cnt += 1
	elif n[0] == '-':
		cnt -= 1
	else:
		a = n.split(':')
		ans += len(a[1]) * cnt
	try:
		n = input()
	except EOFError:
		break
print(ans)


import sys
nb_users = 0
total = 0
for command in sys.stdin:
	if '+' in command:
		nb_users += 1
	elif '-' in command:
		nb_users -= 1
	elif ':' in command:
		total += (len(command.split(':')[1]) - 1) * nb_users
print(total)


from sys import stdin
users = 0
traffic = 0
for i in range(100):
	data = stdin.readline().strip()
	if not data:
		break
	elif data[0] == '+':
		users += 1
	elif data[0] == '-':
		users -= 1
	else:
		traffic += len(data.split(':')[1]) * users
print(traffic)


try:
	(m, n) = (0, 0)
	while True:
		s = input()
		if s[0] == '+':
			m += 1
		elif s[0] == '-':
			m -= 1
		if ':' in s:
			n += (len(s) - s.find(':') - 1) * m
except:
	EOFError
print(n)


cnt = 0
ans = 0
while 1:
	try:
		s = input()
		if s[0] == '+':
			cnt += 1
		elif s[0] == '-':
			cnt -= 1
		else:
			a = s.find(':')
			ans += (len(s) - a - 1) * cnt
	except EOFError:
		break
print(ans)


users = data = 0
contents = []
while True:
	try:
		lines = input()
	except EOFError:
		break
	contents.append(lines)
for line in contents:
	if line[0] == '+':
		users += 1
	elif line[0] == '-':
		users -= 1
	else:
		for i in range(len(line)):
			if line[i] == ':':
				data += len(line[i + 1:len(line)]) * users
print(data)


import sys
z = x = 0
for s in sys.stdin:
	if s[0] == '+':
		x += 1
	elif s[0] == '-':
		x -= 1
	else:
		z += (len(s) - s.find(':') - 2) * x
print(z)


import sys
ans = 0
num = 0
while sys.stdin:
	try:
		cmd = input()
		if cmd[0] == '+':
			num += 1
		elif cmd[0] == '-':
			num -= 1
		else:
			ans += num * len(cmd.split(':')[1])
	except IndexError:
		break
	except EOFError:
		break
print(ans)


import sys
c = t = 0
for i in sys.stdin:
	c += i[0] == '+'
	c -= i[0] == '-'
	if ':' in i:
		t += c * (len(i) - i.find(':') - 2)
print(t)


import sys
l = set()
res = 0
for line in sys.stdin:
	line = line.strip()
	if line[0] == '+':
		name = line[1:]
		l.add(name)
		continue
	if line[0] == '-':
		name = line[1:]
		l.remove(name)
		continue
	text = line.split(':')[1]
	res += len(l) * len(text)
print(res)


import sys
(count, result) = (0, 0)
for line in sys.stdin.readlines():
	if line[0] == '+':
		count += 1
	elif line[0] == '-':
		count -= 1
	else:
		result += count * len(line.strip().split(':')[1])
print(result)


a = input()

def inpt(a):
	cnt = 0
	s = 0
	while a:
		try:
			if a[0] == '+':
				cnt += 1
				a = input()
			elif a[0] == '-':
				cnt -= 1
				a = input()
			else:
				c = a.split(':')[1]
				s += cnt * len(c)
				a = input()
		except:
			return s
print(inpt(a))


from sys import *
live = []
l = 0
for line in stdin:
	if line[0] == '+':
		live.append(line[1:-1])
	elif line[0] == '-':
		live.remove(line[1:-1])
	else:
		idx = line.find(':')
		line = line[idx + 1:]
		l = l + (len(line) - 1) * len(live)
print(l)


t = ''
c = 0
n = 0
while t != 'stop':
	try:
		t = input()
		if t[0] == '+':
			c += 1
		elif t[0] == '-':
			c -= 1
		else:
			i = t.find(':')
			n += c * len(t[i + 1:])
	except:
		t = 'stop'
print(n)


from sys import stdin, stdout
chat_mail = stdin.readline().rstrip()
parts = set()
tr = 0
while len(chat_mail) > 1:
	if chat_mail[0] == '+':
		parts.add(chat_mail[1:])
	elif chat_mail[0] == '-':
		parts.discard(chat_mail[1:])
	else:
		tr += len(chat_mail[chat_mail.find(':') + 1:]) * len(parts)
	chat_mail = stdin.readline().rstrip()
print(tr)


from sys import stdin
cnt = 0
p = 0
while True:
	s = stdin.readline().strip()
	if len(s) <= 1:
		break
	if s[0] == '+':
		p += 1
	elif s[0] == '-':
		p -= 1
	else:
		x = s.find(':')
		cnt += len(s[x + 1:]) * p
print(cnt)


members = 0
size = 0
while 1 > 0:
	try:
		a = input()
		if a[0] == '+':
			members = members + 1
		if a[0] == '-':
			members = members - 1
		for i in range(len(a)):
			if a[i] == ':':
				break
		message = len(a) - i - 1
		size += message * members
	except:
		print(size)
		break


k = 0
s = 0
while True:
	try:
		a = input()
		if a[0] == '+':
			k += 1
		elif a[0] == '-':
			k -= 1
		else:
			s += len(a.split(':')[1]) * k
	except:
		break
print(s)


import sys
n = 0
l = 0
for s in sys.stdin:
	if s[0] == '+':
		n += 1
	elif s[0] == '-':
		n -= 1
	else:
		q = len(s[s.find(':') + 1:])
		q -= 1
		l += q * n
print(l)


people_num = 0
result = 0
while True:
	try:
		src = input()
		if src[0] == '+':
			people_num += 1
		elif src[0] == '-':
			people_num -= 1
		else:
			(a, b) = src.split(':')
			result += people_num * len(b)
	except:
		print(result)
		break


import math
import os
import random
import re
import sys
import functools
from operator import itemgetter, attrgetter
from collections import Counter
Y = lambda : list(map(int, input().split()))
P = lambda : map(int, input().split())
N = lambda : int(input())
(p, ans) = (0, 0)
try:
	while True:
		t = input()
		c = t.find(':')
		if c != -1:
			ans += p * (len(t) - c - 1)
		else:
			p += 1 if t[0] == '+' else -1
except:
	pass
print(ans)


import sys
traffic = users = 0
for command in sys.stdin:
	if command[0] == '+':
		users += 1
	elif command[0] == '-':
		users -= 1
	else:
		traffic += (len(command) - command.find(':') - 2) * users
print(traffic)


cnt = 0
b = 0
import sys
for s in sys.stdin:
	if s[0] == '+':
		cnt += 1
	elif s[0] == '-':
		cnt -= 1
	else:
		b = b + (len(s) - 2 - s.find(':')) * cnt
print(b)


import os
import sys
debug = False
if debug and os.path.exists('input.in'):
	input = open('input.in', 'r').readline
else:
	debug = False
	input = sys.stdin.readline

def inp():
	return int(input())

def inlt():
	return list(map(int, input().split()))

def insr():
	s = input()
	return list(s[:len(s) - 1])

def invr():
	return map(int, input().split())
test_count = 1
if debug:
	test_count = int(input())
for t in range(test_count):
	if debug:
		print('Test Case #', t + 1)
	count = 0
	ans = 0
	for s in sys.stdin:
		if s[0] == '+':
			count += 1
		elif s[0] == '-':
			count -= 1
		else:
			ans += len(s.split(':')[1].strip()) * count
	print(ans)


def readln():
	return tuple(map(int, input().split()))
cnt = ans = 0
while True:
	try:
		inp = input()
		if inp[0] == '+':
			cnt += 1
		elif inp[0] == '-':
			cnt -= 1
		else:
			ans += cnt * len(inp.split(':')[1])
	except:
		break
print(ans)


from sys import stdin
users = set()
size = 0
for line in stdin:
	if line[0] == '+':
		users.add(line[1:])
	elif line[0] == '-':
		users.remove(line[1:])
	else:
		msg = line.split(':', 1)[1].replace('\n', '')
		size += len(msg) * len(users)
print(size)


def main():
	traffic = 0
	person = 0
	try:
		while True:
			cmd = input()
			c = cmd[0]
			if c == '+':
				person += 1
			elif c == '-':
				person -= 1
			else:
				traffic += person * (len(cmd) - cmd.find(':') - 1)
	except EOFError:
		print(traffic)
main()


import sys
bytes = 0
count = 0
lst = []
for n in sys.stdin:
	n = n.rstrip()
	if ':' in n:
		length = len(n[n.index(':') + 1:])
		bytes += count * length
	elif n[1:] in lst:
		lst.remove(n[1:])
		count -= 1
	else:
		lst.append(n[1:])
		count += 1
print(bytes)


import sys
(c, n) = (0, 0)
for sr in sys.stdin:
	if sr[0] == '+':
		n += 1
	elif sr[0] == '-':
		n -= 1
	else:
		i = sr.index(':')
		c += (len(sr) - 2 - i) * n
print(c)


s = 0
a = 0
s = 1
while s:
	try:
		t = input()
	except:
		break
	if len(t) == 0:
		break
	elif t[0] == '+':
		a += 1
	elif t[0] == '-':
		a -= 1
	else:
		s += (len(t) - t.find(':') - 1) * a
print(s - 1)


l = 0
cnt = 0
while True:
	try:
		line = input()
		if line.startswith('+'):
			cnt += 1
		elif line.startswith('-'):
			cnt -= 1
		else:
			l += len(line.split(':')[1]) * cnt
	except:
		break
print(l)


import sys

def main():
	cur = 0
	ans = 0
	for line in sys.stdin:
		line = line.strip()
		if line[0] == '+':
			cur += 1
		elif line[0] == '-':
			cur -= 1
		else:
			l = len(line[line.index(':') + 1:])
			ans += cur * l
	print(ans)
main()


__author__ = 'Darren'

def solve():
	import sys
	stdin = sys.stdin if True else open('data')
	system = set()
	traffic = 0
	for command in stdin:
		command = command.strip()
		if command[0] == '+':
			system.add(command[1:])
		elif command[0] == '-':
			system.remove(command[1:])
		else:
			(name, message) = command.split(':')
			traffic += len(system) * len(message)
	print(traffic)
solve()


import sys
s = 0
n = 0
for i in sys.stdin:
	if i[0] == '+':
		n += 1
	elif i[0] == '-':
		n -= 1
	else:
		s += n * (len(i) - i.find(':') - 2)
print(s)


n = 0
t = 0
while True:
	try:
		cmd = input()
		if cmd[0] == '+':
			n += 1
		elif cmd[0] == '-':
			n -= 1
		else:
			m = cmd[cmd.index(':') + 1:]
			t += len(m) * n
	except EOFError:
		print(t)
		exit(0)


c = 0
otvet = 0
import sys
l = list(map(lambda x: x.strip(), sys.stdin.readlines()))
for s in l:
	if s[0] == '+':
		c = c + 1
	elif s[0] == '-':
		c = c - 1
	else:
		p = (len(s) - s.index(':') - 1) * c
		otvet = otvet + p
print(otvet)


import sys
total = 0
people = 0
for line in sys.stdin.readlines():
	if not line:
		break
	t = line.strip()
	if t.startswith('+'):
		people += 1
	elif t.startswith('-'):
		people -= 1
	else:
		message = t.split(':')[1].strip()
		total += len(message) * people
print(total)


user_num = 0
byte = 0
for i in range(101):
	try:
		s = input()
		if len(s) == 0:
			break
		if s[0] == '+':
			user_num += 1
		elif s[0] == '-':
			user_num -= 1
		else:
			index = s.find(':')
			byte += (len(s) - index - 1) * user_num
	except EOFError:
		break
print(byte)


n = 0
ll = 0
try:
	while True:
		line = input()
		if line.startswith('+'):
			n = n + 1
		elif line.startswith('-'):
			n = n - 1
		else:
			line = line.replace('\n', '')
			if len(line) == 0:
				continue
			x = line.index(':')
			l = len(line) - (x + 1)
			ll += l * n
except EOFError as err:
	print(ll)


kol = 0
ans = 0
while 89 == 89:
	try:
		ins = input()
	except:
		break
	if ins == '':
		break
	if ins[0] == '+':
		kol += 1
	elif ins[0] == '-':
		kol -= 1
	else:
		l = ins.index(':') + 1
		ans += (len(ins) - l) * kol
print(ans)


import sys
a = b = 0
for i in sys.stdin:
	if i[0] == '+':
		a += 1
	elif i[0] == '-':
		a -= 1
	else:
		b += (len(i) - i.find(':') - 2) * a
print(b)


from sys import stdin
joined = 0
traffic = 0
for line in stdin:
	if line[0] == '+':
		joined += 1
	elif line[0] == '-':
		joined -= 1
	else:
		(useless, message) = line.rstrip().split(':')
		traffic += joined * len(message)
print(traffic)


current_users = []

def add_user(user):
	global current_users
	current_users.append(user)

def remove_user(user):
	global current_users
	if user in current_users:
		current_users.remove(user)

def message_byte(message):
	global current_users
	return len(current_users) * len(message)

def get_input():
	while True:
		try:
			line = input()
			if line == '':
				break
			else:
				yield line
		except EOFError:
			break
commands = list(get_input())
all_bytes = 0
for cmd in commands:
	if cmd.startswith('+'):
		add_user(cmd[1:])
	elif cmd.startswith('-'):
		remove_user(cmd[1:])
	else:
		all_bytes += message_byte(cmd.split(':')[1])
print(all_bytes)


import sys
contents = []
participants = 0
sum = 0
while True:
	try:
		s = input()
		contents.append(s)
	except:
		break
for content in contents:
	if content[0] == '+':
		participants += 1
	elif content[0] == '-':
		participants -= 1
	else:
		flash = ':'
		message = content.partition(flash)[2]
		message = message.rstrip('\n')
		traffic = len(message)
		traffic *= participants
		sum += traffic
print(sum)


c = 0
l = []
x = 0
while x == 0:
	try:
		s = input()
		if '+' in s and s[1:] not in l:
			l.append(s[1:])
		if '-' in s and s[1:] in l:
			l.remove(s[1:])
		if ':' in s:
			(a, m) = s.split(':')
			c += len(m) * len(l)
	except:
		x = 1
print(c)


from sys import stdin
ans = 0
myset = set()
for s in stdin:
	s = s[0:-1]
	if s[0] == '+':
		myset.add(s[1:])
	elif s[0] == '-':
		myset.remove(s[1:])
	else:
		ans += len(s.split(':')[1]) * len(myset)
print(ans)


sum = 0
mem = 0
while True:
	try:
		s = input()
		if s[0] == '+':
			mem += 1
		elif s[0] == '-':
			mem -= 1
		else:
			index = s.find(':')
			sum += mem * (len(s) - index - 1)
	except:
		break
print(sum)


import sys
cnt = 0
ans = 0
for s in sys.stdin:
	if s[0] == '+':
		cnt += 1
	elif s[0] == '-':
		cnt -= 1
	else:
		k = s.split(':')
		ans += (len(k[1]) - 1) * cnt
print(ans)


l = []
s = 0
for j in range(101):
	try:
		i = input()
		if i[0] == '+':
			l.append(i[1:])
		elif i[0] == '-':
			l.remove(i[1:])
		elif i.count(':') != 0:
			(p, q) = i.split(':')
			s = s + len(q) * len(l)
	except:
		break
print(s)


import sys
nums = ans = 0
for s in sys.stdin:
	jj = s[0]
	if jj == '+':
		nums += 1
	elif jj == '-':
		nums -= 1
	else:
		(n, t) = s.split(':')
		ans += (len(t) - 1) * nums
print(ans)


import sys

def main():
	participants = 0
	total_length = 0
	while True:
		line = sys.stdin.readline().strip()
		if not line:
			break
		first_char = line[0]
		if first_char == '+':
			participants += 1
		elif first_char == '-':
			participants -= 1
		else:
			total_length += len(line[line.index(':') + 1:]) * participants
	sys.stdout.write(str(total_length) + '\n')
main()


people = []
bw = 0
while True:
	try:
		cmd = input()
		if cmd[0] == '+':
			people.append(cmd[1:])
		elif cmd[0] == '-':
			people.remove(cmd[1:])
		else:
			(_, msg) = cmd.split(':')
			bw += len(msg) * len(people)
	except EOFError:
		break
print(bw)


import sys
__author__ = 'Obriel Muga'
lista = list()
d = dict()
valor = 0
for line in sys.stdin:
	command = line
	if command[0] == '+':
		name = command.strip().split('+')[1]
		d[name] = 1
	elif command[0] == '-':
		name = command.strip().split('-')[1]
		del d[name]
	elif ':' in command:
		(nombre, mensaje) = command.strip().split(':')
		valor = valor + len(d) * len(mensaje)
print(valor)


import re
import sys
ADD_RE = re.compile('\\+(\\w+)', re.ASCII)
REMOVE_RE = re.compile('\\-(\\w+)', re.ASCII)
CHAT_RE = re.compile('\\w+:(.*)', re.ASCII)

def main():
	solve()

def solve():
	data = sys.stdin.readlines()
	chat = parse(data)
	traffic = calc_traffic(chat)
	print(traffic)

def parse(data):
	return tuple((parse_line(line.rstrip()) for line in data))

def parse_line(line):
	m = ADD_RE.match(line)
	if m is not None:
		return ('ADD', m.group(1))
	m = REMOVE_RE.match(line)
	if m is not None:
		return ('REMOVE', m.group(1))
	m = CHAT_RE.match(line)
	if m is not None:
		return ('CHAT', m.group(1))
	assert m is not None, 'Bad string input'

def calc_traffic(chat):
	users = set()
	traffic = 0
	for (command, msg) in chat:
		if command == 'ADD':
			users.add(msg)
		elif command == 'REMOVE':
			users.discard(msg)
		else:
			traffic += len(users) * len(msg)
	return traffic
main()


tot = 0
try:
	ppl = 0
	while True:
		com = input()
		if com[0] == '+':
			ppl += 1
		elif com[0] == '-':
			ppl -= 1
		elif ':' in com:
			tot += ppl * len(':'.join(com.split(':')[1:]))
except:
	print(tot)


arr = set()
c = 0
while 1:
	try:
		s = input()
		if s[0] == '+':
			arr.add(s[1:])
		elif s[0] == '-':
			arr.remove(s[1:])
		else:
			msg = s[s.index(':') + 1:]
			c += len(msg) * len(arr)
	except:
		print(c)
		break


names = []
res = 0
while True:
	try:
		s = input()
	except:
		break
	if s[0] == '+':
		names.append(s[1:])
	elif s[0] == '-':
		names.remove(s[1:])
	elif ':' in s:
		length = len(s.split(':')[1])
		res = res + length * len(names)
	else:
		break
print(res)


import sys
pers = []
sum = 0
for line in sys.stdin:
	if line[0] == '+':
		pers.append(line[1:len(line)])
	elif line[0] == '-':
		pers.remove(line[1:len(line)])
	else:
		str = len(line) - line.find(':') - 2
		sum = sum + str * len(pers)
print(sum)


guys = set()
res = 0
while 1:
	try:
		curRequest = input()
	except:
		break
	if curRequest[0] == '+':
		guys.add(curRequest[1:])
	elif curRequest[0] == '-':
		guys.remove(curRequest[1:])
	else:
		proReq = curRequest[curRequest.find(':') + 1:]
		res += len(proReq) * len(guys)
print(res)


import sys
users = 0
traffic = 0
for line in sys.stdin:
	if line[0] == '+':
		users += 1
	elif line[0] == '-':
		users -= 1
	else:
		line = line.strip().split(':')
		traffic += users * len(line[1])
print(traffic)


a = 0
c = 0
e = 0
d = []
while 1:
	try:
		b = input()
		if b[0] == '+':
			e += 1
		elif b[0] == '-':
			e -= 1
		if b[0] != '+' and b[0] != '-':
			a += (len(b[b.index(':'):]) - 1) * e
	except:
		break
print(a)


import sys
import math
import itertools
import collections

def sieve(n):
	if n < 2:
		return list()
	prime = [True for _ in range(n + 1)]
	p = 3
	while p * p <= n:
		if prime[p]:
			for i in range(p * 2, n + 1, p):
				prime[i] = False
		p += 2
	r = [2]
	for p in range(3, n + 1, 2):
		if prime[p]:
			r.append(p)
	return r

def divs(n, start=1):
	r = []
	for i in range(start, int(math.sqrt(n) + 1)):
		if n % i == 0:
			if n / i == i:
				r.append(i)
			else:
				r.extend([i, n // i])
	return r

def cdiv(n, k):
	return n // k + (n % k != 0)

def ii():
	return int(input())

def mi():
	return map(int, input().split())

def li():
	return list(map(int, input().split()))

def lcm(a, b):
	return abs(a * b) // math.gcd(a, b)

def wr(arr):
	return ''.join(map(str, arr))

def revn(n):
	return str(n)[::-1]

def prime(n):
	if n == 2:
		return True
	if n % 2 == 0 or n <= 1:
		return False
	sqr = int(math.sqrt(n)) + 1
	for d in range(3, sqr, 2):
		if n % d == 0:
			return False
	return True

def convn(number, base):
	newnumber = 0
	while number > 0:
		newnumber += number % base
		number //= base
	return newnumber
chat = set()
ans = 0
while True:
	try:
		s = input()
		if s == '':
			break
		elif s[0] == '+':
			chat.add(s[1:])
		elif s[0] == '-':
			chat.remove(s[1:])
		else:
			pos = s.find(':')
			ans += len(s[pos + 1:]) * len(chat)
	except EOFError:
		break
print(ans)


import sys
name = 0
flow = 0
try:
	while True:
		line = sys.stdin.readline().strip()
		if not line:
			break
		elif line[0] == '+':
			name += 1
		elif line[0] == '-':
			name -= 1
		else:
			count = 0
			found = False
			while line[count] != ':':
				count += 1
			flow += name * (len(line) - count - 1)
except:
	pass
print(flow)


(k, m) = (0, 0)
while True:
	try:
		line = str(input())
	except:
		break
	if line[0] == '+':
		m += 1
	elif line[0] == '-':
		m -= 1
	else:
		k += m * len(line[line.index(':') + 1:])
print(k)


n = 0
t = 0
while True:
	try:
		l = input()
		if l[0] == '+':
			n += 1
		elif l[0] == '-':
			n -= 1
		else:
			t += n * len(l.split(':')[1])
	except:
		break
print(t)


import sys
from typing import List, Union

def rl(int_: bool=True, is_split: bool=True) -> Union[List[str], List[int]]:
	if int_:
		return [int(w) for w in sys.stdin.readline().split()]
	if is_split:
		return [w for w in sys.stdin.readline().split()]
	return sys.stdin.readline().strip()
lines = sys.stdin.read().split('\n')
n = len(lines)
names = set()
t = 0
l = 0
for i in range(n - 1):
	line = lines[i]
	if line[0] == '+':
		names.add(line[1:].strip())
		l += 1
	elif line[0] == '-':
		names.remove(line[1:].strip())
		l -= 1
	else:
		t += l * len(line.strip().split(':')[1])
print(t)


import sys
(s, u) = (0, 0)
for line in sys.stdin:
	if line[0] == '+':
		u += 1
	elif line[0] == '-':
		u -= 1
	else:
		s += len(line.rstrip().split(':')[1]) * u
print(s)


(ans, num) = (0, 0)
while True:
	try:
		s = input()
		if s[0] == '+':
			num += 1
		elif s[0] == '-':
			num -= 1
		else:
			ans += len(s.split(':')[1]) * num
	except:
		exit(print(ans))


import sys
u = 0
result = 0
for answer in sys.stdin:
	if answer[0] == '+':
		u += 1
	elif answer[0] == '-':
		u -= 1
	else:
		result += u * (len(answer) - answer.find(':') - 2)
print(result)


import sys
users = []
ans = 0
for s in sys.stdin:
	if s[0] == '+':
		users.append(s[1:])
	elif s[0] == '-':
		del users[users.index(s[1:])]
	else:
		ans += len(users) * (len(s[s.index(':') + 1:]) - 1)
print(ans)


import sys
(users, ans) = (list(), 0)
for line in sys.stdin:
	line = line.rstrip()
	if line[0] == '+':
		users.append(line[1:])
	elif line[0] == '-':
		users.remove(line[1:])
	else:
		ind = line.index(':')
		msg = line[ind + 1:]
		ans += len(msg) * len(users)
print(ans)


from sys import stdin
nb = 0
users = 0
while True:
	command = stdin.readline().strip()
	if len(command) <= 1:
		break
	if command[0] == '+':
		users += 1
	elif command[0] == '-':
		users -= 1
	else:
		nb += len(command.split(':')[1]) * users
print(nb)


import sys
people = 0
ans = 0
for m in sys.stdin:
	if m[0] == '+':
		people += 1
	elif m[0] == '-':
		people -= 1
	else:
		ans += (len(m) - m.find(':') - 2) * people
print(ans)


n = 0
try:
	i = 0
	while True:
		m = input()
		if m[0] == '+':
			n += 1
		elif m[0] == '-':
			n -= 1
		else:
			i += len(m.split(':')[1]) * n
except:
	pass
print(i)


from sys import stdin
(count1, count2) = (0, 0)
for elem in stdin:
	count1 += elem[0] == '+'
	count1 -= elem[0] == '-'
	count2 += (':' in elem) * count1 * (len(elem) - elem.find(':') - 2)
print(count2)


import os
import sys
from io import BytesIO, IOBase
import math
from decimal import *
from collections import defaultdict, deque
import heapq
getcontext().prec = 25
abcd = 'abcdefghijklmnopqrstuvwxyz'
MOD = pow(10, 9) + 7
BUFSIZE = 8192
from bisect import bisect_left, bisect_right

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
ans = 0
s = list()
for i in range(100):
	a = input()
	if not a:
		break
	elif a[0] == '+':
		s.append(a[1:])
	elif a[0] == '-':
		s.pop(s.index(a[1:]))
	else:
		f = a.find(':')
		ans += len(s) * len(a[f + 1:])
print(ans)


import sys
(t, n) = (0, 0)
for s in sys.stdin:
	s = s.strip()
	if s == '':
		break
	if s[0] == '+':
		n += 1
	elif s[0] == '-':
		n -= 1
	else:
		msg = s.strip().split(':')[1]
		t += n * len(msg)
print(t)


a = 0
b = 0
while True:
	try:
		s = input()
	except EOFError:
		break
	if s[0] == '-':
		a = a - 1
	elif s[0] == '+':
		a = a + 1
	else:
		b = b + a * len(s.split(':')[1])
print(b)


from sys import stdin
people = ans = 0
for line in stdin:
	if line[0] == '+':
		people += 1
	elif line[0] == '-':
		people -= 1
	else:
		ans += (len(line) - line.find(':') - 2) * people
print(ans)


def main():
	res = cnt = 0
	f = '+-'.find
	try:
		while True:
			s = input()
			sig = f(s[0])
			if sig >= 0:
				cnt += 1 - sig * 2
			else:
				res += cnt * len(s[s.find(':') + 1:].strip())
	except:
		print(res)
main()


import sys
ans = 0
l = 0
n = []
for s in sys.stdin:
	if s[0] == '+':
		l += 1
	elif s[0] == '-':
		l -= 1
	else:
		for k in range(len(s)):
			if s[k] == ':':
				ans += l * (len(s) - k - 2)
				break
print(ans)


traffic = 0
users = 0
import sys
input_main = sys.stdin.read()
input_l = input_main.splitlines()
for st in input_l:
	if st[0] == '+':
		users += 1
	elif st[0] == '-':
		users -= 1
	else:
		l = len(st[st.find(':') + 1:])
		traffic += l * users
print(traffic)


member = 0
count = 0
while 1:
	try:
		l = input().split(':')
	except EOFError:
		break
	if l[0][0] == '+':
		member += 1
	elif l[0][0] == '-':
		member -= 1
	else:
		count += len(l[1]) * member
print(count)


def judge(string):
	if string[0] == '+':
		return 1
	elif string[0] == '-':
		return 2
	elif ':' in string:
		return 3

def get_text(string):
	idx = string.find(':')
	text = string[idx + 1:]
	return text

def get_name(string):
	name = string[1:]
	return name

def main():
	import sys
	traffic = 0
	alist = []
	for line in sys.stdin:
		if judge(line) == 1:
			name = get_name(line)
			alist.append(name)
		elif judge(line) == 2:
			name = get_name(line)
			alist.remove(name)
		elif judge(line) == 3:
			t = get_text(line)
			traffic = traffic + (len(t) - 1) * len(alist)
	print(traffic)
main()


s = set()
t = 0
while True:
	try:
		c = input()
	except EOFError:
		break
	if c[0] == '+':
		s.add(c[1:])
	elif c[0] == '-':
		s.remove(c[1:])
	else:
		t += len(s) * (len(c) - c.find(':') - 1)
print(t)


cnt = 0
Sum = 0
while 1:
	try:
		tmp = input()
		if tmp[0] == '+':
			cnt += 1
		elif tmp[0] == '-':
			cnt -= 1
		else:
			p = tmp.find(':')
			Sum += len(tmp[p + 1:]) * cnt
	except:
		break
print(Sum)


import sys
result = 0
n = 0
for answer in sys.stdin:
	if answer[0] == '+':
		n += 1
	elif answer[0] == '-':
		n -= 1
	else:
		result += n * (len(answer.split(':')[1]) - 1)
print(result)


from sys import stdin
lines = stdin.read().splitlines()
Chat_members = []
Bites = 0
Bench = ''
Switch = 0
for line in lines:
	if line[0] == '+':
		for i in range(len(line)):
			if i == len(line) - 1:
				break
			Bench = Bench + str(line[i + 1])
		Chat_members.append(Bench)
	elif line[0] == '-':
		for i in range(len(line)):
			if i == len(line) - 1:
				break
			Bench = Bench + str(line[i + 1])
		Chat_members.remove(Bench)
	else:
		for i in range(len(line)):
			if Switch == 1:
				Bench = Bench + str(line[i])
			if line[i] == ':':
				Switch = 1
		Bites = Bites + len(Chat_members) * len(Bench)
	Bench = ''
	Switch = 0
print(Bites)


arr = []
cnt = 0
while 1:
	try:
		s = input()
	except EOFError as e:
		break
	if s == '':
		break
	if ord(s[0]) == 43:
		index = 0
		s = s[:index] + s[index + 1:]
		arr.append(s)
	elif ord(s[0]) == 45:
		index = 0
		s = s[:index] + s[index + 1:]
		arr.remove(s)
	elif s.split(':')[0] in arr:
		cnt += len(s.split(':')[1]) * len(arr)
print(cnt)


count = 0
active = 0
while True:
	try:
		inputStr = input()
		if '+' in inputStr:
			active += 1
		elif '-' in inputStr:
			active -= 1
		else:
			count += len(inputStr.split(':')[1]) * active
	except:
		print(count)
		break


import sys
trafic = 0
s = set()
for request in sys.__stdin__:
	if request[0] == '+':
		s.add(request[1:])
	elif request[0] == '-':
		s.remove(request[1:])
	else:
		trafic += len(request[request.find(':') + 1:-1]) * len(s)
print(trafic)


from sys import stdin
p = 0
load = 0
while True:
	s = stdin.readline().strip()
	if len(s) <= 1:
		break
	if s[0] == '+':
		p += 1
	elif s[0] == '-':
		p -= 1
	else:
		load += len(s.split(':')[1]) * p
print(load)


import sys
(traffic, users) = (0, 0)
for st in sys.stdin.read().splitlines():
	if st[0] == '+':
		users += 1
		continue
	elif st[0] == '-':
		users -= 1
		continue
	else:
		traffic += len(st[st.find(':') + 1:]) * users
print(traffic)


def rr():
	return input().rstrip()

def rri():
	return int(rr())

def rrl():
	return list(map(int, rr().split()))

def rrt():
	return tuple(map(int, rr().split()))
from collections import defaultdict

def mus(d=lambda : 0):
	return defaultdict(lambda : defaultdict(d))

def dd0(d=lambda : 0):
	return defaultdict(d)

def ms(x, y, d=0):
	return [[0] * y for i in range(x)]

def ar(x, d=0):
	return [d] * x

def ppm(m, n=0, x=0, y=0):
	print('\n'.join(('\t'.join((str(m[j][i]) for j in range(y or n))) for i in range(x or n))))

def ppa(a, n):
	print('\t'.join(map(str, a[0:n])))

def ppl(a=0, x=[1]):
	x[0] = a or x[0] + 1
	print('-' + '- -' * 14 + '-# ' + str(x[0] - 2) + ' #-' + '- -' * 14 + '-')

def fltn(a):
	(i for sub in a for i in sub)

def yn(x):
	return 'YES' if x else 'NO'
from itertools import accumulate
from itertools import groupby

def grp(x):
	return ((i, sum((1 for _ in g))) for (i, g) in groupby(x))
import math

def rnar():
	return (*rrl(), rrl())

def rn():
	return (*rrl(),)

def read():
	return (0,)

def solve(__):
	cur_clients = set()
	td = 0
	while True:
		try:
			ci = input()
		except Exception:
			break
		if ci.startswith('+'):
			cur_clients.add(ci[1:])
		elif ci.startswith('-'):
			cur_clients.remove(ci[1:])
		else:
			(sn, sd) = ci.split(':', 1)
			td += len(sd) * len(cur_clients)
	ans = td
	return ans
test_count = 1
for _ in range(test_count):
	input_data = read()
	result = solve(*input_data)
	print(result)


from sys import stdin
p = 0
bytes = 0
for msg in stdin:
	msg = msg.strip()
	if msg[0] == '+':
		p += 1
	elif msg[0] == '-':
		p -= 1
	else:
		msg = msg[msg.find(':') + 1:]
		bytes += len(msg) * p
print(bytes)


import re
from collections import Counter

class Task:
	commands = []
	answer = 0

	def getData(self):
		while True:
			try:
				str = input()
			except EOFError:
				break
			self.commands += [str]

	def solve(self):
		peopleCount = 0
		for current in self.commands:
			if current[0] == '+':
				peopleCount += 1
			elif current[0] == '-':
				peopleCount -= 1
			else:
				self.answer += peopleCount * len(current.split(':')[1])

	def printAnswer(self):
		print(self.answer)
task = Task()
task.getData()
task.solve()
task.printAnswer()


ans = 0
n = 0
while True:
	try:
		line = input()
	except:
		break
	if line[0] == '+':
		n += 1
	elif line[0] == '-':
		n -= 1
	else:
		ans += len(line.split(':')[-1]) * n
print(ans)


def CF_5A():
	n = 0
	traffic = 0
	while True:
		try:
			line = input()
			if line[0] == '+':
				n += 1
			elif line[0] == '-':
				n -= 1
			else:
				traffic += n * len(line.split(':')[1])
		except:
			break
	print(traffic)
	return
CF_5A()


x = 0
count = 0
while True:
	try:
		n = input()
		if '+' in n:
			count += 1
		if '-' in n:
			count -= 1
		if ':' in n:
			i = n.index(':')
			x += len(n[i + 1:]) * count
	except EOFError:
		break
print(x)


import sys
group = 0
size = 0
for line in sys.stdin:
	if line[0] == '+':
		group += 1
	elif line[0] == '-':
		group -= 1
	else:
		size += group * len(line.strip().split(':')[1])
print(size)


traffic = 0
members = 0
while True:
	try:
		chat = input()
		if chat[0] == '+':
			members += 1
		elif chat[0] == '-':
			members -= 1
		if chat[0] != '+' and chat[0] != '-':
			traffic += (len(chat[chat.index(':'):]) - 1) * members
	except:
		break
print(traffic)


try:
	name = []
	cnt = 0
	while 1:
		p = input()
		if p[0] == '+':
			name.append(p[1:])
		elif p[0] == '-':
			name.remove(p[1:])
		else:
			q = p.index(':')
			cnt += len(name) * (len(p) - q - 1)
except EOFError:
	print(cnt)


import sys
res = 0
users = {}
for line in sys.stdin:
	if ':' in line:
		(_, message_text) = line.split(':')
		res += len(users) * (len(message_text) - 1)
	else:
		command = line[0]
		name = line[1:]
		if command == '+':
			users[name] = 1
		else:
			users.pop(name)
print(res)


import sys
person = 0
ans = 0
for st in sys.stdin:
	if st[0] == '+':
		person += 1
	elif st[0] == '-':
		person -= 1
	else:
		ans += person * (len(st) - st.find(':') - 2)
print(ans)


import sys
k = 0
s = 0
for line in sys.stdin:
	if line == '\n':
		break
	if line[0] == '+':
		k += 1
	if line[0] == '-':
		k -= 1
	if line[0] != '+' and line[0] != '-':
		s += (len(line) - line.index(':') - 2) * k
print(s)


ans = 0
x = 0
while 1:
	try:
		a = input()
		if a == '':
			break
		if a[0] == '+':
			x += 1
		elif a[0] == '-':
			x -= 1
		else:
			ans += len(a.split(':')[-1]) * x
	except:
		break
print(ans)


from sys import stdin
active = traffic = 0
for line in stdin:
	active += line[0] == '+'
	active -= line[0] == '-'
	if ':' in line:
		traffic += active * (len(line) - line.find(':') - 2)
print(traffic)


import sys
c = 0
ans = 0
for l in sys.stdin:
	if l[0] == '+':
		c += 1
	if l[0] == '-':
		c -= 1
	if ':' in l:
		ans += c * (len(l) - l.find(':') - 2)
print(ans)


ans = 0
active = 0
while True:
	try:
		str = input()
		if not str:
			break
		if str[0] == '+':
			active = active + 1
		elif str[0] == '-':
			active = active - 1
		else:
			ans = ans + active * len(str.split(':')[1])
	except EOFError:
		break
print(ans)


from sys import stdin

def ifplus(name, members):
	members.append(name.replace('+', ''))

def ifminus(name, members):
	members.remove(name.replace('-', ''))

def counttraffic(line, members):
	delete = line.find(':')
	line = line[delete + 1:]
	return (len(line) - 1) * len(members)

def getFileData():
	members = []
	traffic = 0
	for line in stdin:
		if line[0] == '+':
			ifplus(line, members)
		elif line[0] == '-':
			ifminus(line, members)
		else:
			traffic += counttraffic(line, members)
	print(traffic)
getFileData()


res = 0
cnt = 0
while True:
	try:
		src = input()
		if src[0] != '+' and src[0] != '-':
			(l, r) = src.split(':')
			res += cnt * len(r)
		elif src[0] == '+':
			cnt += 1
		else:
			cnt -= 1
	except:
		print(res)
		break


import sys
t = p = 0
for l in sys.stdin:
	if l[0] == '+':
		p = p + 1
	elif l[0] == '-':
		p = p - 1
	elif ':' in l:
		t = t + p * (len(l) - (l.find(':') + 2))
print(t)


import sys
import bisect

def gcd(a, b):
	if a == 0:
		return b
	return gcd(b % a, a)

def input():
	return sys.stdin.readline().strip()

def iinput():
	return int(input())

def minput():
	return map(int, input().split())

def listinput():
	return list(map(str, input().split()))
(peeps, tra) = (0, 0)
for i in sys.stdin:
	if i[0] == '+':
		peeps += 1
	elif i[0] == '-':
		peeps -= 1
	else:
		tra += (len(i) - 2 - i.find(':')) * peeps
print(tra)


import math
from sys import stdin
users = []
traffic = 0
for line in stdin:
	if line[0] == '+':
		users.append(line[1:])
	if line[0] == '-':
		users.remove(line[1:])
	if line == '\n':
		break
	loc = None
	for i in range(0, len(line)):
		if line[i] == ':':
			loc = i
			size = len(line) - loc - 2
			traffic += size * len(users)
print(traffic)


from sys import stdin
(t, p) = (0, 0)
for line in stdin.readlines():
	line = line.strip()
	if line[0] == '+':
		p += 1
	elif line[0] == '-':
		p -= 1
	else:
		t += p * (len(line) - line.index(':') - 1)
print(t)


__author__ = 'Darren'

def solve():
	import sys
	stdin = sys.stdin if True else open('data')
	users = 0
	traffic = 0
	for command in stdin:
		command = command.strip()
		if command[0] == '+':
			users += 1
		elif command[0] == '-':
			users -= 1
		else:
			(name, message) = command.split(':')
			traffic += users * len(message)
	print(traffic)
solve()


import sys
a = sys.stdin.readlines()
cnt = 0
vol = 0
for s in a:
	s = s.strip()
	if s[0] == '+':
		cnt += 1
	elif s[0] == '-':
		cnt -= 1
	else:
		p = s.find(':')
		s = s[p + 1:]
		vol += cnt * len(s)
print(vol)


import sys
participants = 0
total_bytes = 0
for line in sys.stdin:
	if not line.strip():
		break
	first = line[0]
	if first == '+':
		participants += 1
	elif first == '-':
		participants -= 1
	else:
		msg = line.split(':')[1]
		total_bytes += len(msg.strip()) * participants
print(total_bytes)


l = []
while 1:
	try:
		l.append(input())
	except:
		break
c = 0
le = 0
for i in l:
	if i[0] == '+':
		c = c + 1
	elif i[0] == '-':
		c = c - 1
	else:
		le = le + c * len(i[i.index(':') + 1:])
print(le)


(n, l) = (0, 0)
while True:
	try:
		command = input()
		if command[0] == '+':
			n += 1
		elif command[0] == '-':
			n -= 1
		else:
			l += (len(command[command.index(':'):]) - 1) * n
	except EOFError:
		break
print(l)


dct = dict()
output = 0
while True:
	try:
		input_str = input()
		if input_str[:1] == '+':
			dct[input_str[1:]] = 0
		elif input_str[:1] == '-':
			if dct[input_str[1:]] == 0:
				dct.pop(input_str[1:], None)
		else:
			output += len(input_str[input_str.index(':') + 1:]) * len(dct)
	except:
		break
print(output)


s = set()
n = 0
while 1:
	try:
		c = input()
		if c[0] == '+':
			s.add(c[1:])
			continue
		if c[0] == '-':
			s.remove(c[1:])
			continue
		n += len(s) * len(c.split(':')[1])
	except:
		break
print(n)


import sys
a = t = 0
for s in sys.stdin:
	if s[0] == '+':
		t += 1
	elif s[0] == '-':
		t -= 1
	else:
		a += t * (len(s) - s.find(':') - 2)
print(a)


import sys
traffic = 0
num_par = 0

def compute_traffic(num_par, len_msg):
	return num_par * len_msg

def process_line(num_par, traffic, line):
	if line[0] == '+':
		num_par += 1
	elif line[0] == '-':
		num_par -= 1
	elif line != '\n':
		len_msg = len(line.split(':')[1]) - 1
		traffic += compute_traffic(num_par, len_msg)
	return (num_par, traffic)
for line in sys.stdin:
	(num_par, traffic) = process_line(num_par, traffic, line)
print(traffic)


res = 0
n = 0
import sys
for s in sys.stdin:
	if s[0] == '+':
		n += 1
	elif s[0] == '-':
		n -= 1
	elif s.find(':') != -1:
		(name, msg) = s.split(':')
		res += n * (len(msg) - 1)
print(res)


from sys import stdin

class A:

	def solve(self):
		users = set()
		byte_data = 0
		for line in stdin:
			if line.startswith('+'):
				users.add(line[1:])
			elif line.startswith('-'):
				users.remove(line[1:])
			else:
				data = line.split(':')
				data[1] = data[1][:-1]
				byte_data += len(data[1]) * len(users)
		print(byte_data)
A().solve()


b = 0
c = 0
while True:
	try:
		a = input()
	except:
		break
	d = 0
	if a[0] == '+':
		b += 1
	elif a[0] == '-':
		b -= 1
	else:
		for i in range(0, len(a)):
			if a[i] == ':' and d == 0:
				c += (len(a) - i - 1) * b
				d = 1
print(c)


import sys
a = b = 0
for m in sys.stdin:
	a += m[0] == '+'
	a -= m[0] == '-'
	b += (':' in m) * (len(m) - m.find(':') - 2) * a
print(b)


import sys
ans = 0
users = []
for line in sys.stdin:
	line = line.rstrip('\n')
	command = line[0]
	if command == '+':
		users.append(line[1:])
	elif command == '-':
		users.remove(line[1:])
	else:
		message = line[line.index(':') + 1:]
		ans += len(message) * len(users)
print(ans)


from sys import stdin
count = 0
l = 0
while True:
	s = stdin.readline().strip()
	if len(s) <= 1:
		break
	if s[0] == '+':
		count += 1
	elif s[0] == '-':
		count -= 1
	else:
		l += count * len(s[s.index(':') + 1:])
print(l)


import sys

def calculate_traffic(commands):
	traffic = 0
	users = 0
	for command in commands:
		if command[0] == '+':
			users += 1
		elif command[0] == '-':
			users -= 1
		else:
			traffic += len(command.split(':')[1]) * users
	return traffic

def main(sinp=sys.stdin, sout=sys.stdout):
	commands = sinp.read().rstrip().split('\n')
	sout.write(str(calculate_traffic(commands)))
main()


B = 0
D = {}
while 1:
	try:
		r = input()
		if r[0] == '+':
			D[r[1:]] = 1
		elif r[0] == '-':
			D[r[1:]] = 0
		else:
			o = r.find(':')
			B += len(r[o + 1:]) * sum(D.values())
	except EOFError:
		print(B)
		break


ans = 0
size = 0
while True:
	try:
		command = input()
		if command[0] == '+':
			size += 1
		elif command[0] == '-':
			size -= 1
		else:
			ans += len(command.split(':')[1]) * size
	except:
		break
print(ans)


users = 0
bandwidth = 0
while True:
	try:
		text = input()
	except EOFError:
		break
	if text[0] == '+':
		users += 1
	elif text[0] == '-':
		users -= 1
	else:
		bandwidth += users * len(text.split(':')[1])
print(bandwidth)


chat = []
try:
	while True:
		inp = input()
		if inp != '':
			chat.append(inp)
		else:
			break
except EOFError:
	pass
ans = 0
c = 0
for ele in chat:
	if ele[0] == '-':
		c -= 1
	elif ele[0] == '+':
		c += 1
	else:
		l = 0
		for ch in ele:
			if ch == ':':
				break
			else:
				l += 1
		ans += c * (int(len(ele)) - l - 1)
print(ans)


ans = 0
people = 0
for x in range(100):
	try:
		a = input()
		if a[0] == '+':
			people += 1
		elif a[0] == '-':
			people -= 1
		else:
			ans += len(a.split(':')[1]) * people
	except:
		break
print(ans)


from sys import stdin
import re
people = 0
ans = 0
for line in stdin:
	if line[0] == '+':
		people += 1
	elif line[0] == '-':
		people -= 1
	else:
		msg = re.compile(':(.*)').search(line).group().replace(':', '')
		ans += len(msg) * people
print(ans)


import sys
p = x = 0
for s in sys.stdin.readlines():
	if s[0] == '+':
		p += 1
	elif s[0] == '-':
		p -= 1
	else:
		x += p * (len(s) - s.find(':') - 2)
print(x)


from collections import deque, defaultdict, Counter
from itertools import product, groupby, permutations, combinations
from math import gcd, floor, inf
from bisect import bisect_right, bisect_left
from sys import stdin
ans = 0
people = 0
for s in stdin:
	if s.startswith('-'):
		people -= 1
	elif s.startswith('+'):
		people += 1
	else:
		ans += len(s.rstrip().split(':')[1]) * people
print(ans)


import sys
serverTraffic = 0
activeUsers = 0
for line in sys.stdin:
	if line[0] == '+':
		activeUsers += 1
	elif line[0] == '-':
		activeUsers -= 1
	else:
		serverTraffic += activeUsers * (len(line) - line.find(':') - 2)
print(serverTraffic)


from sys import stdin
users = set([])
traffic = 0
for line in stdin:
	line = line.strip()
	if line[0] == '+':
		users.add(line[1:])
	elif line[0] == '-':
		users.remove(line[1:])
	else:
		content = line[line.find(':') + 1:]
		traffic += len(users) * len(content)
print(traffic)


l = []
count = 0
while True:
	try:
		x = input()
		if x[0] == '+':
			l.append(x[1:])
		elif x[0] == '-':
			l.remove(x[1:])
		else:
			(a, b) = x.split(':')
			count += len(l) * len(b)
	except:
		print(count)
		break


n = 0
per = []
l = 0
while n != 100:
	try:
		enter = input()
	except EOFError as e:
		break
	for i in range(len(enter)):
		if enter[0] == '+':
			per.append(enter[1:])
			break
		elif enter[0] == '-':
			per.remove(enter[1:])
			break
		elif ':' in enter:
			(_, message) = enter.split(':')
			l += len(message) * len(per)
			break
	if enter == '':
		break
	n += 1
print(l)


from sys import stdin
a = stdin.readlines()
ans = 0
users = 0
for i in a:
	if i.startswith('+'):
		users += 1
	elif i.startswith('-'):
		users -= 1
	else:
		ans += len(i[i.find(':') + 2:]) * users
print(ans)


import sys
(users, ans) = ([], 0)
for line in sys.stdin:
	line = line.rstrip()
	if line[0] == '+':
		users.append(line[1:])
	elif line[0] == '-':
		users.remove(line[1:])
	else:
		c = line.index(':')
		ans += len(line[c + 1:]) * len(users)
print(ans)


class ChatServer:

	@classmethod
	def parseCommand(cls, commandString):
		if commandString[0] == '+':
			return {'A': 'Add', 'U': commandString.split('+')[1].split('\n')[0]}
		elif commandString[0] == '-':
			return {'A': 'Remove', 'U': commandString.split('-')[1].split('\n')[0]}
		else:
			content = commandString.split(':')
			return {'A': 'Send', 'S': content[0], 'M': content[1].split('\n')[0]}

	@classmethod
	def updateChatServerWith(cls, commandPacket):
		if commandPacket['A'] == 'Add':
			ChatServer.persons.add(commandPacket['U'])
		elif commandPacket['A'] == 'Remove':
			ChatServer.persons.remove(commandPacket['U'])
		else:
			userCount = len(ChatServer.persons)
			ChatServer.traffic += userCount * len(commandPacket['M'])
	(persons, traffic) = (set(), 0)
import sys
for command in sys.stdin:
	ChatServer.updateChatServerWith(ChatServer.parseCommand(command))
print(ChatServer.traffic)


from sys import stdin
s = stdin.readline()
k = 0
ans = 0
while s != '':
	if s[0] == '+':
		k += 1
	elif s[0] == '-':
		k -= 1
	else:
		for i in range(len(s)):
			if s[i] == ':':
				ans += k * (len(s) - i - 2)
				break
	s = stdin.readline()
print(ans)


import sys
ans = 0
users = []
for Line in sys.stdin:
	cmd = Line[0]
	if cmd == '+':
		users.append(Line[1:].rstrip())
	elif cmd == '-':
		users.remove(Line[1:].rstrip())
	else:
		ind = Line.index(':')
		msg = Line[ind + 1:].rstrip()
		ans += len(users) * len(msg)
print(ans)


from sys import stdin
users = set()
s = 0
for i in stdin:
	line = i.strip()
	if line[0] == '+':
		users.add(line[1:])
	elif line[0] == '-':
		users.discard(line[1:])
	else:
		(login, message) = line.split(':')
		s += len(message) * len(users)
print(s)


from sys import stdin
ans = 0
npp = 0
for line in stdin:
	if line[0] == '+':
		npp += 1
		continue
	if line[0] == '-':
		npp -= 1
		continue
	ans += npp * (len(line.split(':')[1]) - 1)
print(ans)


from sys import stdin
people = []
ans = 0
for line in stdin:
	line = line.strip()
	if line[0] == '+':
		people.append(line[1:])
	elif line[0] == '-':
		people.remove(line[1:])
	else:
		msg_len = len(line.split(':')[1])
		ans += msg_len * len(people)
print(ans)


l = []
name = ''
num = 0
while True:
	try:
		name = input()
	except:
		break
	if name[0] == '+':
		l.append(name[1:])
	elif name[0] == '-':
		l.remove(name[1:])
	else:
		pos = name.find(':')
		num += (name.__len__() - pos - 1) * l.__len__()
print(num)


import sys
n = 0
total = 0
while True:
	try:
		cmd = input()
	except EOFError:
		break
	else:
		if cmd[0] == '+':
			n += 1
		elif cmd[0] == '-':
			n -= 1
		else:
			msg = cmd.split(':')[-1]
			total += n * len(msg)
print(total)


u = set()
r = 0
for s in [*open(0)]:
	if s[0] == '+':
		u |= {s[1:-1]}
	elif s[0] == '-':
		u -= {s[1:-1]}
	else:
		r += len(u) * len(s.split(':')[1][:-1])
print(r)


import sys
kuser = 0
ltext = 0
for mes in sys.stdin:
	if mes[0] == '+':
		kuser += 1
	elif mes[0] == '-':
		kuser -= 1
	else:
		ltext += kuser * (len(mes) - mes.find(':') - 2)
print(ltext)


import math as mt
import sys, string, bisect
input = sys.stdin.readline
from collections import deque
L = lambda : list(map(int, input().split()))
Ls = lambda : list(input().split())
M = lambda : map(int, input().split())
I = lambda : int(input())
c = 0
ans = 0
while True:
	s = input().strip()
	if s == '':
		break
	if s[0] == '+':
		c += 1
	elif s[0] == '-':
		c -= 1
	else:
		x = s.split(':')
		ans += c * len(x[1].strip())
print(ans)


from sys import stdin
s = stdin.read().split('\n')
length = 0
users = 0
s.pop()
for line in s:
	if line[0] == '+':
		users += 1
	elif line[0] == '-':
		users -= 1
	else:
		l = line.split(':')
		length += len(l[1]) * users
print(length)


import sys
ans = 0
c = 0
for s in sys.stdin:
	s = s.strip()
	if ':' in s:
		ans += (len(s) - s.index(':') - 1) * c
	elif s[0] == '+':
		c += 1
	else:
		c -= 1
print(ans)


import sys
users = set()
cnt = 0
for line in sys.stdin:
	if line[0] == '+':
		users.add(line.strip()[1:])
	elif line[0] == '-':
		users.discard(line.strip()[1:])
	else:
		cnt += len(line.strip()[line.index(':') + 1:]) * len(users)
print(cnt)


p = []
u = 0
while True:
	try:
		a = input()
		if a[0] == '+':
			p.append(a[1:])
		elif a[0] == '-':
			p.remove(a[1:])
		else:
			b = a.split(':')
			u += len(b[-1]) * len(p)
	except:
		print(u)
		break


l = []
m = 0
while True:
	try:
		name = input()
		if ':' in name and name.split(':')[0] in l:
			message = len(name.split(':')[1])
			m += len(l) * message
		elif '+' in name and name[1:] not in l:
			l.append(name[1:])
		elif '-' in name and name[1:] in l:
			l.remove(name[1:])
	except:
		break
print(m)


signcount = 0
result = 0
while True:
	try:
		a = input()
	except:
		break
	d = 0
	if a[0] == '+':
		signcount += 1
	elif a[0] == '-':
		signcount -= 1
	else:
		for i in range(0, len(a)):
			if a[i] == ':' and d == 0:
				result += (len(a) - i - 1) * signcount
				d = 1
print(result)


import sys
people = 0
total = 0
try:
	for i in sys.stdin:
		if i[0] == '+':
			people += 1
		elif i[0] == '-':
			people -= 1
		else:
			string = i.split(':')[1]
			total += people * (len(string) - 1)
except:
	pass
print(total)


import sys
c = t = 0
for l in sys.stdin:
	c += l[0] == '+'
	c -= l[0] == '-'
	t += (':' in l) * c * (len(l) - l.find(':') - 2)
print(t)


import sys
keyuser = 0
lentext = 0
for message in sys.stdin:
	if message[0] == '+':
		keyuser += 1
	elif message[0] == '-':
		keyuser -= 1
	else:
		lentext += keyuser * (len(message) - message.find(':') - 2)
print(lentext)


(commands, joined, send) = ([], 0, 0)
while True:
	try:
		string = input()
		if string != '':
			commands.append(string)
		else:
			break
	except EOFError:
		break
for com in commands:
	if com[0] == '-':
		joined -= 1
	elif com[0] == '+':
		joined += 1
	else:
		send += joined * len(com.split(':')[1])
print(send)


import sys
import math
res = 0
c = 0
for line in sys.stdin.readlines():
	if line[0] == '+':
		c += 1
	elif line[0] == '-':
		c -= 1
	else:
		res += c * (len(line.split(':')[1]) - 1)
print(res)


import sys
lines = sys.stdin.read().splitlines()
users = 0
traffic = 0
for l in lines:
	if l[0] == '+':
		users += 1
	elif l[0] == '-':
		users -= 1
	else:
		traffic += users * len(l.split(':')[1])
print(traffic)


people_count = 0
traffic = 0
while True:
	try:
		command = input()
	except:
		break
	if command == '':
		break
	if command[0] == '+':
		people_count += 1
	elif command[0] == '-':
		people_count -= 1
	else:
		traffic += len(command.split(':')[1]) * people_count
print(traffic)


res = ''
users = []
while True:
	try:
		l = input()
		if '+' in l:
			users.append(l[1:])
		elif '-' in l:
			users.remove(l[1:])
		elif '+' not in l and '-' not in l:
			res += l.split(':')[1] * len(users)
	except:
		break
print(len(res))


ans = 0
try:
	n = 0
	while True:
		s = input()
		if s[0] == '+':
			n += 1
		elif s[0] == '-':
			n -= 1
		else:
			ans += len(s.split(':')[1]) * n
except:
	pass
print(ans)


import sys
txt = [line.strip() for line in sys.stdin]
people = {}
a = 0
for line in txt:
	if line[0] == '+':
		people[line[1:]] = 1
	elif line[0] == '-':
		del people[line[1:]]
	else:
		b = line.index(':')
		a += len(line[b + 1:]) * len(people)
print(a)


def get_input():
	try:
		s = input()
		return s
	except EOFError:
		return ''
names = []
sum = 0
while True:
	S = get_input()
	if S == '':
		break
	if S[0] == '+':
		names.append(S[1:])
	elif S[0] == '-':
		for i in range(0, len(names)):
			if names[i] == S[1:]:
				names.pop(i)
				break
	else:
		writenmes = S.split(':')[1]
		sum += len(names) * len(writenmes)
print(sum)


import sys
commands = sys.stdin.read()
commands = commands.split('\n')
commands.pop()
traffic = 0
d = {}
for command in commands:
	if command[0] == '+':
		d[command[1:len(command)]] = ''
	elif command[0] == '-':
		del d[command[1:len(command)]]
	else:
		message = command.split(':')[1]
		traffic += len(d) * len(message)
print(traffic)


ss = set()
ans = 0
while 1:
	try:
		s = input()
		if s[0] == '+':
			ss.add(s[1:])
		elif s[0] == '-':
			ss.remove(s[1:])
		else:
			ans += len(s.split(':')[1]) * len(ss)
	except EOFError:
		break
print(ans)


def main():
	ppl = set()
	b = 0
	while True:
		try:
			l = input()
		except EOFError:
			break
		if len(l) == 0:
			break
		if l[0] == '+':
			ppl.add(l[1:])
		elif l[0] == '-':
			ppl.remove(l[1:])
		else:
			b += len(ppl) * (len(l) - l.find(':') - 1)
	print(b)
main()


(cnt, res) = (0, 0)
try:
	while 1:
		s = input()
		if s[0] == '+':
			cnt += 1
		elif s[0] == '-':
			cnt -= 1
		else:
			res += cnt * (len(s) - s.find(':') - 1)
except EOFError:
	print(res)


import sys
users = 0
traf = 0
while True:
	try:
		t = input()
		if t[0] == '+':
			users += 1
		elif t[0] == '-':
			users -= 1
		else:
			traf += len(t.split(':')[1]) * users
	except:
		break
print(traf)


import sys
number = 0
mem = 0
for a in sys.stdin:
	if a[0] == '+':
		number += 1
	elif a[0] == '-':
		number -= 1
	else:
		mem += len(a[a.find(':') + 1:-1]) * number
print(mem)


import sys
(c, r) = (0, 0)
for s in sys.stdin.readlines():
	if s[0] == '+':
		c += 1
	elif s[0] == '-':
		c -= 1
	elif ':' in s:
		r += c * (len(s.split(':')[1]) - 1)
print(r)


ll = []
c = 0
while True:
	try:
		s = input()
		if s[0] == '+':
			ll.append(s[1:])
		elif s[0] == '-':
			ll.remove(s[1:])
		else:
			c += len(s[s.find(':') + 1:]) * len(ll)
	except EOFError:
		print(c)
		break