k = int(input().strip())
n = input().strip()
ln = len(n)
val_n = 0
for x in range(ln):
    val_n += int(n[x])
print(val_n)
if val_n >= k:
    print(0)

else:
    val = 0
    valsDiff = 0
    min_n = 9
    while val_n < k:
        min_n = 9
        for x in range(ln):
            if int(n[x]) < min_n:
                min_n = int(n[x])
        for x in range(ln):
            if int(n[x]) == min_n:
                val = x
                break
        n = n[:val] + '9' + n[val+1:]
        val_n -= min_n
        val_n += 9
        valsDiff += 1
        print(val_n)
    print(valsDiff)


k = int(input())

n = int(input())

lst = []
while(n>0):
    lst.append(n%10)
    n //= 10

if sum(lst) >= k:
    print(0)
else:
    count = 0
    while(sum(lst)<k):
        lst[count] = 9
        count += 1
    print(count)


k = int(input())

n = input()

lst = list(map(int, n))

if sum(lst) >= k:
    print(0)
else:
    count = 0
    while(sum(lst)<k):
        lst[count] = 9
        count += 1
    print(count)


k = int(input())

n = input()

lst = list(map(int, n))
lst.sort()

if sum(lst) >= k:
    print(0)
else:
    count = 0
    while(sum(lst)<k):
        lst[count] = 9
        count += 1
    print(count)


k = int(input())

n = input()

lst = list(map(int, n))
summation = sum(lst)

if summation >= k:
    print(0)
else:
    lst.sort()
    count = 0
    while(summation<k):
        summation += (9-lst[count])
        count += 1
    print(count)


k = int(input())

n = int(input())

lst = []
while(n>0):
    lst.append(n%10)
    n //= 10

if sum(lst) > k:
    print(0)
else:
    count = 0
    while(sum(lst)<k):
        lst[count] = 9
        count += 1
    print(count)


k = int(input())

n = input()

lst = list(map(int, a))

if sum(lst) >= k:
    print(0)
else:
    count = 0
    while(sum(lst)<k):
        lst[count] = 9
        count += 1
    print(count)


def main():
    K = int(input())
    N = input()

    k = sum(map(int, N))
    if k >= K:
        ans = 0
    else:
        n = list(map(int, N))
        k2 = K - k
        for i in range(len(n) - 1, 0, -1):
            j = 9 - n[i]
            if k2 >= j:
                n[i] += j
                k2 -= j
            else:
                n[i] += k2
                break

        n = ''.join(map(str, n))
        ans = len(str(int(n) - int(N)))

    print(ans)

main()


def main():
    K = int(input())
    N = input()

    k = sum(map(int, N))
    if k >= K:
        ans = 0
    else:
        n = list(map(int, N[::-1]))
        k2 = K - k
        for i in range(len(n)):
            j = 9 - n[i]
            if k2 >= j:
                n[i] += j
                k2 -= j
            else:
                n[i] += k2
                break

        n = ''.join(map(str, n[::-1]))
        ans = len(str(int(n) - int(N)))

    print(ans)

main()


def main():
    K = int(input())
    N = input()

    n = sorted(list(map(int, N)))
    k2 = sum(n)
    if k2 >= K:
        ans = 0
    else:
        i = 0
        while k2 < K:
            j = 9 - n[i]
            n[i] = 9
            k2 += j
            i += 1
        ans = i

    print(ans)

main()


def main():
    K = int(input())
    N = input()

    k = sum(map(int, N))
    if k >= K:
        ans = 0
    else:
        n = int(N) + K - k
        ans = len(str(n - int(N)))

    print(ans)

main()


def main():
    K = int(input())
    N = input()

    k = sum(map(int, list(N)))
    if k >= K:
        ans = 0
    else:
        n = int(N)
        while k < K:
            n += 1
            k = sum(map(int, list(str(n))))
        ans = len(str(abs(int(N) - n)))

    print(ans)

main()


def main():
    K = int(input())
    N = input()

    k = sum(map(int, N))
    if k >= K:
        ans = 0
    else:
        n = list(map(int, N))
        k2 = K - k
        for i in range(0, len(n), -1):
            j = 9 - n[i]
            if k2 >= j:
                n[i] += j
                k2 -= j
            else:
                n[i] += k2
                break

        n = ''.join(map(str, n))
        ans = len(str(int(n) - int(N)))

    print(ans)

main()


k = int(input())
n = input()
counter = [0 for x in range(0,10)]
sum = 0;
for x in n:
    sum += int(x);
    counter[int(x)]+=1;
if sum>=k:
    print(0);
else:
	ans = 0;
	for x in range(0,10):
		if sum+counter[x]>=k:
			ans = sum+counter[x]-k;
		else:
			ans += sum+counter[x];

	print(ans);


k = int(input())
n = input()
counter = [0 for x in range(0,10)]
sum = 0;
for x in n:
    sum += int(x);
    counter[int(x)]+=1;
if sum>=k:
    print(0);
else:
	ans = 0;
	for x in range(0,10):
		if counter[x]==0:
			continue;
		if sum+counter[x]>=k:
			ans = sum+counter[x]-k;
		else:
			ans += sum+counter[x];

	print(ans);


import math;
k = int(input())
n = input()
counter = [0 for x in range(0,10)]
sum = 0;
for x in n:
    sum += int(x);
    counter[int(x)]+=1;
if sum>=k:
    print(0);
else:
	ans = 0;
	for x in range(0,10):
		if counter[x]==0:
			continue;
		if sum+(counter[x]*9)>=k:
			ans += math.ceil((k - sum)/9);
			break;
		else:
			ans += counter[x];
			sum += counter[x]*9;

	print(ans);


import math;
k = int(input())
n = input()
counter = [0 for x in range(0,10)]
sum = 0;
for x in n:
    sum += int(x);
    counter[int(x)]+=1;
if sum>=k:
    print(0);
else:
	ans = 0;
	for x in range(0,10):
		if counter[x]==0:
			continue;
		if sum+(counter[x]*(9-x))>=k:
			ans += math.ceil((k - sum)/(9-x));
			break;
		else:
			ans += counter[x];
			sum += counter[x]*(9-x);

	print(ans);


k = int(input())
n = input()
counter = [0 for x in range(0,10)]
sum = 0;
for x in n:
    sum += int(x);
    counter[int(x)]+=1;
if sum>=k:
    print(0);
    return 0;
ans = 0;
for x in range(0,10):
    if sum+counter[x]>=k:
        ans = sum+counter[x]-k;
    else:
        ans += sum+counter[x];

print(ans);


k = int(input())
n = input()
counter = [0 for x in range(0,10)]
sum = 0;
for x in n:
    sum += int(x);
    counter[int(x)]+=1;
if sum>=k:
    print(0);
    return 0;
for x in range(0,10):
    if sum+counter[x]>=k:
        ans = sum+counter[x]-k;
    else
        ans += sum+counter[x];

print(ans);


import math;
k = int(input())
n = input()
counter = [0 for x in range(0,10)]
sum = 0;
for x in n:
    sum += int(x);
    counter[int(x)]+=1;
if sum>=k:
    print(0);
else:
	ans = 0;
	for x in range(0,10):
		if counter[x]==0:
			continue;
		if sum+(counter[x]*9)>=k:
			ans += math.ceil((k - sum)/9);
			break;
		else:
			ans += counter[x];
			sum += counter[x]*(9-x);

	print(ans);


k = int(input())
n = input()
c = [0]*10
summ = 0
for s in n:
    c[int(s)]+=1
    summ += int(s)

if summ>=k:
    print(0)
else:
    zam = 0
    for i in range(0,9):
        if (k - summ) - (c[9-i]*(9-i)) > 0:
            zam+=c[9-i]
            summ+=c[9-i]*(9-i)
        else:
            temp = (k-summ)//(9-i)
            summ += temp*(9-i)
            zam  += temp
    print(zam)


k = int(input())
n = input()
c = [0]*10
summ = 0
for s in n:
    c[int(s)]+=1
    summ += int(s)
zam = 0

for i in range(0,9):
    if summ>=k:
        break
    if (k - summ) - c[i]*(9-i) >= 0:
        zam += c[i]
        summ += c[i]*(9-i)
    else:
        temp = (k-summ)//(9-i)
        if (k-summ)%(9-i) >0 : temp+=1
        summ += temp*(9-i)
        zam  += temp

print(zam)


k = int(input())
n = input()
c = [0]*10
summ = 0
for s in n:
    c[int(s)]+=1
    summ += int(s)

if summ>=k:
    print(0)
else:
    zam = 0
    for i in range(0,9):
        if (k - summ) - (c[9-i]*(9-i)) >= 0:
            zam+=c[9-i]
            summ+=c[9-i]*(9-i)
        else:
            temp = (k-summ)//(9-i)
            summ += temp*(9-i)
            zam  += temp
    print(zam)


k = int(input())
n = sorted(list(map(int, list(input()))))

s = sum(n)
count = 0
i = 0
while s < k and i < len(n):
    s += 9 - n[i]
    count += 1

print(count)


k = int(input())
n = sorted(list(map(int, list(input()))))

s = sum(n)

count = 0
i = 0
for x in n:
    if s < k:
        s += 9 - x
        count += 1
    else:
        break

print(count)


k=int(input())
n=list(input())
for i in range(len(n)):
    n[i]=int(n[i])
i=1
while sum(n)<k:
    n[-i]=9
    i+=1
print(i-1)


k=int(input())
n=list(input())
for i in range(len(n)):
    n[i]=int(n[i])
n=sorted(n)
i=0
while sum(n)<k:
    n[i]=9
    i+=1
print(i)


k=int(input())
n=list(input())
for i in range(len(n)):
    n[i]=int(n[i])
n=sorted(n)
i=0
d=sum(n)
while d<k:
    d+=9-n[i]
    i+=1

print(i)


k = int(input())
n = input()
s = sum(list(map(int, n)))
if s >= k:
    print(0)
else:
    d = [0] * 9
    for i in range(0, 9):
        d[i] = n.count(str(i))
    c = 0
    dif = k - s
    for i in range(0, 9):
        if dif > d[i] * (9-i):
            dif -= d[i] * (9-i)
            c += d[i]
        else:
            cur = dif // (9-i)
            if dif % (9-i) != 0:
                cur += 1
            c += cur
            break
    print(c)


k = int(input())
n = input()
s = sum(list(map(int, n)))
if s >= k:
    print(0)
else:
    d = [0] * 9
    for i in range(1, 9):
        d[i] = n.count(str(i))
    c = 0
    dif = k - s
    for i in range(1, 10):
        if dif > d[i] * (9-i):
            dif -= d[i] * (9-i)
            c += i
        else:
            cur = dif // (9-i)
            if dif % (9-i) != 0:
                cur += 1
            c += cur
            break
    print(c)


k = int(input())
n = input()
s = sum(list(map(int, n)))
if s >= k:
    print(0)
else:
    d = [0] * 9
    for i in range(1, 9):
        d[i] = n.count(str(i))
    c = 0
    dif = k - s
    for i in range(1, 10):
        if dif > d[i] * (9-i):
            dif -= d[i] * (9-i)
            c += i
        else:
            cur = dif // (9-i)
            c += cur
            break
    print(c)


k = int(input())
n = input()
s = sum(list(map(int, n)))
if s >= k:
    print(0)
else:
    d = [0] * 9
    for i in range(0, 9):
        d[i] = n.count(str(i))
    c = 0
    dif = k - s
    for i in range(0, 9):
        if dif > d[i] * (9-i):
            dif -= d[i] * (9-i)
            c += i
        else:
            cur = dif // (9-i)
            if dif % (9-i) != 0:
                cur += 1
            c += cur
            break
    print(c)


def digit_list(i):
	return [int(j) for j in str(i)]

k = int(input())
n = int(input())

sum_n = sum(digit_list(n))

if sum_n >= k:
	print(0)
else:
	#differ = k - sum_n
	#differ_lsit = digit_list(differ)
	print(sum(digit_list(k-sum_n)))


def digit_list(i):
	str_i = str(i)
	list_i = list(str_i)
	for j in range(len(list_i)):
		list_i[j] = int(list_i[j])
	return list_i

k = int(input())
n = int(input())

list_n = digit_list(n)

if sum(list_n) >= k:
	print(0)
else:
	differ = 1
	while True:
		if sum(digit_list(n + differ)) == k:
			print(differ)
			break
		if sum(digit_list(n - differ)) == k:
			print(differ)
			break
		differ += 1


def digit_list(i):
	return [int(j) for j in str(i)]

k = int(input())
n = int(input())

list_n = digit_list(n)

if sum(list_n) >= k:
	print(0)
else:
	differ = 1
	while True:
		if sum(digit_list(n + differ)) == k:
			print(differ)
			break
		if sum(digit_list(n - differ)) == k:
			print(differ)
			break
		differ += 1


def digit_list(i):
	return [int(j) for j in str(i)]

k = int(input())
n = int(input())

sum_n = sum(digit_list(n))

if sum_n >= k:
	print(0)
else:
	differ = k - sum_n
	n_list = digit_list(n)
	n_list.sort()
	#print(n_list)
	total = 0
	for i in range(len(n_list)):
		total += (9 - n_list[i])
		#print(total)
		if total >= differ:
			print(i + 1)
			break


n=int(input())
b=list(input())
for i in range(len(b)):
    b[i]=int(b[i])
z=sum(b)
if z>=n:
    print(0)
else:
    t=0
    while sum(b)<n:
        z=b.index(min(b))
        b[z]=9
        t+=1
    print(t)


n=int(input())
b=list(input())
for i in range(len(b)):
    b[i]=int(b[i])
z=sum(b)
#print(z)
if z>=n:
    print(0)
else:
    t=0
    h=n-z
    te=9*[0]
    for i in range(9):
        te[i]=b.count(i)
    te2=9*[0]
    for i in range(9):
        te2[i]=(9-i)*te[i]
    te3=9*[0]
    for i in range(9):
        te3[i]=sum(te2[:i+1])
    while h>te3[t]:
        t+=1
    m=0
    for i in range(t):
        m+=te[i]
        h-=te2[i]
    if h%(9-t)==0:
        m+=h//(9-t)
    else:
        m+=h//(9-t)+1
    #print(t)
    print(m)
    #print(te,te2,te3)


n=int(input())
b=list(input())
for i in range(len(b)):
    b[i]=int(b[i])
z=sum(b)
if z>=n:
    print(0)
else:
    t=0
    h=n-z
    te=9*[0]
    for i in range(9):
        te[i]=b.count(i)
    te2=9*[0]
    for i in range(9):
        te2[i]=(9-i)*te[i]
    te3=9*[0]
    for i in range(9):
        te3[i]=sum(te2[:i+1])
    while h>te3[t]:
        t+=1
    m=0
    for i in range(t):
        m+=te3[i]
        h-=m*(9-i)
    if h%(9-t)==0:
        m+=h//(9-t)
    else:
        m+=h//(9-t)+1
    print(m)


k = int(input())
s = list(input())
s = sorted(s)
sint = list(map(int,s))
print(sint)
ssum = sum(sint)
print(ssum)
if(ssum >= k):
	print("0")
else:
	ssum = ssum - k
	i=0
	c=0
	while(i<len(s)):
		ssum = ssum + 9 - sint[i];
		c += 1
		if(ssum>=0):
			break
		i += 1
	# print("::")
	print(c)


k = int(input())
s = list(input())
s = sorted(s)
sint = list(map(int,s))
ssum = sum(sint)
# print(ssum)
if(ssum >= k):
	print("0")
else:
	ssum = ssum - k
	i=0
	c=0
	while(i<len(s)):
		ssum = ssum + 9 - sint[i];
		c += 1
		if(ssum>0):
			break
		i += 1
	# print("::")
	print(c)


k = int(input())
s = list(input())
s = sorted(s)
sint = list(map(int,s))
# print(sint)
ssum = sum(sint)
# print(ssum)
if(ssum >= k):
	print("0")
else:
	ssum = ssum - k
	i=0
	c=0
	while(i<len(s)):
		ssum = ssum + 9 - sint[i];
		c += 1
		if(ssum>=0):
			break
		i += 1
	# print("::")
	print(c)


k=int(input())
n=input()
x=[]
nn=0
d=0
for i in range(len(n)):
    x.append(int(n[i]))
for m in range(len(n)):
    nn=nn+x[m]
if nn>=k:
    print('0')
else:
    x.sort()
    p=0
    while(nn<k):
        nn+=(9-x[p])
        p+=1
        d=d+1
    print(d)


k=int(input())
n=input()
x=[]
nn=0
d=0
for i in range(len(n)):
    x.append(int(n[i]))
for m in range(len(n)):
    nn=nn+x[m]
if nn>=k:
    print('0')
else:
    x.sort()
    p=0
    while(nn<k):
        nn+=(9-x[p])
        p+=1
        d=d+1
print(d)


import sys
n, k = sys.stdin.read().split()
sum_k = 0
for x in str(k):
    sum_k = sum_k + ord(x) - ord('0')

if sum_k > int(n):
    print(0)
else:
    print(1)


import sys
n, k = sys.stdin.read().split()
sum_k = 0
for x in str(k):
    sum_k = sum_k + ord(x) - ord('0')

if sum_k >= int(n):
    print(0)
else:
    l = sorted(str(k))
    cnt = 0
    for x in l:
        if sum_k - (ord(x) - ord('0')) + 9 >= int(n):
            cnt += 1
            break
        else:
            sum_k = sum_k - (ord(x) - ord('0')) + 9
            cnt += 1
    print(cnt)


import sys
n, k = sys.stdin.read().split()
sum_k = 0
for x in str(k):
    sum_k = sum_k + ord(x) - ord('0')

if sum_k >= int(n):
    print(0)
else:
    l = sorted(str(k))
    cnt = 0
    for x in l:
        if sum_k - (ord(x) - ord('0')) + 9 >= int(k):
            break
        else:
            sum_k = sum_k - (ord(x) - ord('0')) + 9
            cnt += 1
    print(cnt)


import sys
n, k = sys.stdin.read().split()
sum_k = 0
for x in str(k):
    sum_k = sum_k + ord(x) - ord('0')

if sum_k > int(n) or int(n) == 1:
    print(0)
else:
    print(1)


import sys
n, k = sys.stdin.read().split()
sum_k = 0
for x in str(k):
    sum_k = sum_k + ord(x) - ord('0')
if sum_k >= int(n):
    print(0)
else:
    print(1)


k = eval(input())
n = input()

array = []

for char in n:
	array.append(ord(char) - ord('0'))
array.sort()

value = sum(array)
count = 0

for i in digit:
	if value < k:
		value += 9 - i
		count += 1
print(count)


k = eval(input())
n = input()

array = []

for char in n:
	array.append(ord(char) - ord('0'))
array.sort()
value = sum(array)
count = 0

for i in array:
	if value < k:
		value += 9 - i
		count += 1
print(count)


k = eval(input())
n = input()

array = []

for char in n:
	array.append(ord(char) - ord('0'))
array.sort()
print(array)
value = sum(array)
print(value)
count = 0

for i in array:
	if value < k:
		value += 9 - i
		count += 1
print(count)


# -*- coding: utf-8 -*-
"""
Created on Mon Sep 24 21:09:52 2018

@author: brian
"""
k=int(input())
n=sum(list(map(int,list(input()))))
if(k>n):
    print(k-n)
else:
    print("0")


# -*- coding: utf-8 -*-
"""
Created on Mon Sep 24 21:09:52 2018

@author: brian
"""
k=int(input())
s=sorted(list(map(int,list(input()))))
n=sum(s)
if(k>n):
    counter=0
    for i in s:
        if(n<k):
            n+=9-int(i)
            counter+=1
        else:
            break
    print(counter)
else:
    print("0")


k = int(input())
n = input()

def digitsum(s):
	su = 0
	for i in range(len(s)):
		su += int(s[i])

	return su

dig = digitsum(n)

if(dig >= k):
	print(0)
else:
	rep = 0
	diff = 0
	for i in range(len(n)):
		diff = 9 - int(n[i])
		dig = dig + diff
		rep += 1
		if(dig >= k):
			break

	print(rep)


    /** Author :- Kumar Vijyant From MNNIT **/

    #include<bits/stdc++.h>
    using namespace std;
    #define sz(a) (int)(a.size())
    #define all(a) a.begin(),a.end()
    typedef unsigned long long llu;
    typedef  long long ll;
    typedef vector<int> vi;
    typedef vector<bool> vb;
    typedef vector<string> vs;
    typedef vector<ll> vll;
    typedef vector<vector<int>>  vvi ;
    typedef pair<int,int> pi;
    typedef vector<pair<int,int>> vpi ;
    #define F first
    #define S second
    #define pb push_back
    #define mp make_pair
    #define endl "\n"
    #define int ll
    #define precise(n) cout<<fixed<<setprecision(int n)
    #ifdef LOCAL
    #include "debug.h"
    #else
    #define debug(...) 42
    #endif
    const int mod=1e9+7;
    const double e = 1e-9;
    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
    template <typename A, typename B>istream& operator>>(istream& input,pair<A,B>& x) {input>>x.F>>x.S;return input;}
    template <typename A>istream& operator>>(istream& input,vector<A>& x) {for(auto& i:x)	input>>i;return input;}
    template<typename A>ostream& operator<<(ostream& output,vector<A>& x) {for(auto& i:x)	output<<i<<' ';	return output;}
    void add(int&,int );
    int sub(int ,int );
    int mul(int,int);
    int powz(int ,int );
    ll binpow(int , int );
    int gcd(int ,int);
    bool sortinrev(const pair<char,int>a,pair<char,int>b){ return (a.S<b.S);}
    bool Compdoub( double a , double b ) { if((a-b)<e)return 1; else return 0; }
    template < typename T> void smax(T& a , T b){ a = max(a,b); }
    template < typename T> void smin(T& a , T b){ a = min(a,b); }
    /***************************************************main code**************************************************************/
    const int N=1e6+5;
    const int inf = 1e9+100;

    void solve()
    {
		string s[105];

		int i = 0;

		int tot_msg = 0;
		int mem = 0;

		while(getline(cin,s[i]))
		{
			if(s[i][0] == '+')mem++;
			else if(s[i][0] == '-')mem--;
			else
			{
				debug(mem);
				debug(s[i]);
				int pos = s[i].find(':');
				tot_msg += (mem * (sz(s[i])-pos-1));
				debug(tot_msg);
			}
			i++;
		}

		cout <<tot_msg;

    }
    /*************----------------------------******************/
    signed main(){
    	ios_base::sync_with_stdio(false);
    	cin.tie(0);
    	int tc=1;
    	//~ cin>>tc;
    	for(int _=0;_<tc;_++){
    		//~ cout<<"Case #"<<_+1<<": ";
    		solve();
    		if(_!=tc-1)
    		cout<<"\n";
    	}

    }
    ll binpow(int a, int b)
     {    ll res = 1;
    	 while (b > 0){
    		 if(b & 1)res = res*a;
    		  a = a *1ll*a;
    		   b >>= 1;
    	  }
       return res;
     }
    int powz(int a,int b)
    {
    	int res=1;
    	while(b)
    	{
    		if(b&1)res=mul(res,a);
    		b/=2;
    		a=mul(a,a);
    	}
    	return res;
    }
    int gcd(int a ,int b){
    	if(b ==0)return a;
    	return gcd(b,a%b);
    }
    int sub(int a,int b){
    	a-=b;
    	if(a<0){
    		a+=mod;
    	}
    	return a;
    }
    int mul(int a,int b)
    {
    	return ((a)*1ll*(b))%mod;
    }
    void add(int &a,int b)
    {
    	a+=b;
    	if(a>=mod)a-=mod;
    }


    /** Author :- Kumar Vijyant From MNNIT **/

    #include<bits/stdc++.h>
    using namespace std;
    #define sz(a) (int)(a.size())
    #define all(a) a.begin(),a.end()
    typedef unsigned long long llu;
    typedef  long long ll;
    typedef vector<int> vi;
    typedef vector<bool> vb;
    typedef vector<string> vs;
    typedef vector<ll> vll;
    typedef vector<vector<int>>  vvi ;
    typedef pair<int,int> pi;
    typedef vector<pair<int,int>> vpi ;
    #define F first
    #define S second
    #define pb push_back
    #define mp make_pair
    #define endl "\n"
    #define int ll
    #define precise(n) cout<<fixed<<setprecision(int n)
    #ifdef LOCAL
    #include "debug.h"
    #else
    #define debug(...) 42
    #endif
    const int mod=1e9+7;
    const double e = 1e-9;
    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
    template <typename A, typename B>istream& operator>>(istream& input,pair<A,B>& x) {input>>x.F>>x.S;return input;}
    template <typename A>istream& operator>>(istream& input,vector<A>& x) {for(auto& i:x)	input>>i;return input;}
    template<typename A>ostream& operator<<(ostream& output,vector<A>& x) {for(auto& i:x)	output<<i<<' ';	return output;}
    void add(int&,int );
    int sub(int ,int );
    int mul(int,int);
    int powz(int ,int );
    ll binpow(int , int );
    int gcd(int ,int);
    bool sortinrev(const pair<char,int>a,pair<char,int>b){ return (a.S<b.S);}
    bool Compdoub( double a , double b ) { if((a-b)<e)return 1; else return 0; }
    template < typename T> void smax(T& a , T b){ a = max(a,b); }
    template < typename T> void smin(T& a , T b){ a = min(a,b); }
    /***************************************************main code**************************************************************/
    const int N=1e6+5;
    const int inf = 1e9+100;
    int msg(string s)
    {
		int pos = s.find(':');
		int len = sz(s) - pos-1;
		//~ debug(s);
		//~ string str = s.substr(pos+1);
		//~ debug(str);
		//~ debug(len);
		return len;
	}

    void solve()
    {
		string s[101];

		set<string>st;
		int tot_msg = 0;
		int cnt1= 0;
		int cnt2 =0;

		for(int i = 0 ; i < 100 ; ++i)
		{
			getline(cin,s[i]);
			if(s[i][0] == '+')
			{
				cnt1++;
				string str = s[i].substr(1);
				debug(str);
				st.insert(str);
			}
			else if(s[i][0] == '-')
			{
				cnt2++;
				string str = s[i].substr(1);
				debug(str);
				st.erase(str);
			}
			else
			{
				debug(s[i]);
				int n = sz(st);
				tot_msg += n*msg(s[i]);
			}
			debug(st);
			if( cnt1 == cnt2 and cnt1 >2)break;
		}

		cout <<tot_msg;

    }
    /*************----------------------------******************/
    signed main(){
    	ios_base::sync_with_stdio(false);
    	cin.tie(0);
    	int tc=1;
    	//~ cin>>tc;
    	for(int _=0;_<tc;_++){
    		//~ cout<<"Case #"<<_+1<<": ";
    		solve();
    		if(_!=tc-1)
    		cout<<"\n";
    	}

    }
    ll binpow(int a, int b)
     {    ll res = 1;
    	 while (b > 0){
    		 if(b & 1)res = res*a;
    		  a = a *1ll*a;
    		   b >>= 1;
    	  }
       return res;
     }
    int powz(int a,int b)
    {
    	int res=1;
    	while(b)
    	{
    		if(b&1)res=mul(res,a);
    		b/=2;
    		a=mul(a,a);
    	}
    	return res;
    }
    int gcd(int a ,int b){
    	if(b ==0)return a;
    	return gcd(b,a%b);
    }
    int sub(int a,int b){
    	a-=b;
    	if(a<0){
    		a+=mod;
    	}
    	return a;
    }
    int mul(int a,int b)
    {
    	return ((a)*1ll*(b))%mod;
    }
    void add(int &a,int b)
    {
    	a+=b;
    	if(a>=mod)a-=mod;
    }


    /** Author :- Kumar Vijyant From MNNIT **/

    #include<bits/stdc++.h>
    using namespace std;
    #define sz(a) (int)(a.size())
    #define all(a) a.begin(),a.end()
    typedef unsigned long long llu;
    typedef  long long ll;
    typedef vector<int> vi;
    typedef vector<bool> vb;
    typedef vector<string> vs;
    typedef vector<ll> vll;
    typedef vector<vector<int>>  vvi ;
    typedef pair<int,int> pi;
    typedef vector<pair<int,int>> vpi ;
    #define F first
    #define S second
    #define pb push_back
    #define mp make_pair
    #define endl "\n"
    #define int ll
    #define precise(n) cout<<fixed<<setprecision(int n)
    #ifdef LOCAL
    #include "debug.h"
    #else
    #define debug(...) 42
    #endif
    const int mod=1e9+7;
    const double e = 1e-9;
    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
    template <typename A, typename B>istream& operator>>(istream& input,pair<A,B>& x) {input>>x.F>>x.S;return input;}
    template <typename A>istream& operator>>(istream& input,vector<A>& x) {for(auto& i:x)	input>>i;return input;}
    template<typename A>ostream& operator<<(ostream& output,vector<A>& x) {for(auto& i:x)	output<<i<<' ';	return output;}
    void add(int&,int );
    int sub(int ,int );
    int mul(int,int);
    int powz(int ,int );
    ll binpow(int , int );
    int gcd(int ,int);
    bool sortinrev(const pair<char,int>a,pair<char,int>b){ return (a.S<b.S);}
    bool Compdoub( double a , double b ) { if((a-b)<e)return 1; else return 0; }
    template < typename T> void smax(T& a , T b){ a = max(a,b); }
    template < typename T> void smin(T& a , T b){ a = min(a,b); }
    /***************************************************main code**************************************************************/
    const int N=1e6+5;
    const int inf = 1e9+100;
    int msg(string s)
    {
		int pos = s.find(':');
		int len = sz(s) - pos-1;
		//~ debug(s);
		//~ string str = s.substr(pos+1);
		//~ debug(str);
		//~ debug(len);
		return len;
	}

    void solve()
    {
		string s[105];

		set<string>st;
		int tot_msg = 0;
		int i = 0;

			while(getline(cin,s[i]))
			{

				if(s[i][0] == '+')
				{

					string str = s[i].substr(1);
					//~ debug(str);
					st.insert(str);

				}
				else if(s[i][0] == '-')
				{
					string str = s[i].substr(1);
					//~ debug(str);
					st.erase(str);
				}
				else
				{
					//~ debug(s[i]);
					int n = sz(st);
					tot_msg += n*msg(s[i]);
				}
				i++;
			}

		cout <<tot_msg;

    }
    /*************----------------------------******************/
    signed main(){
    	ios_base::sync_with_stdio(false);
    	cin.tie(0);
    	int tc=1;
    	//~ cin>>tc;
    	for(int _=0;_<tc;_++){
    		//~ cout<<"Case #"<<_+1<<": ";
    		solve();
    		if(_!=tc-1)
    		cout<<"\n";
    	}

    }
    ll binpow(int a, int b)
     {    ll res = 1;
    	 while (b > 0){
    		 if(b & 1)res = res*a;
    		  a = a *1ll*a;
    		   b >>= 1;
    	  }
       return res;
     }
    int powz(int a,int b)
    {
    	int res=1;
    	while(b)
    	{
    		if(b&1)res=mul(res,a);
    		b/=2;
    		a=mul(a,a);
    	}
    	return res;
    }
    int gcd(int a ,int b){
    	if(b ==0)return a;
    	return gcd(b,a%b);
    }
    int sub(int a,int b){
    	a-=b;
    	if(a<0){
    		a+=mod;
    	}
    	return a;
    }
    int mul(int a,int b)
    {
    	return ((a)*1ll*(b))%mod;
    }
    void add(int &a,int b)
    {
    	a+=b;
    	if(a>=mod)a-=mod;
    }


    /** Author :- Kumar Vijyant From MNNIT **/

    #include<bits/stdc++.h>
    using namespace std;
    #define sz(a) (int)(a.size())
    #define all(a) a.begin(),a.end()
    typedef unsigned long long llu;
    typedef  long long ll;
    typedef vector<int> vi;
    typedef vector<bool> vb;
    typedef vector<string> vs;
    typedef vector<ll> vll;
    typedef vector<vector<int>>  vvi ;
    typedef pair<int,int> pi;
    typedef vector<pair<int,int>> vpi ;
    #define F first
    #define S second
    #define pb push_back
    #define mp make_pair
    #define endl "\n"
    #define int ll
    #define precise(n) cout<<fixed<<setprecision(int n)
    #ifdef LOCAL
    #include "debug.h"
    #else
    #define debug(...) 42
    #endif
    const int mod=1e9+7;
    const double e = 1e-9;
    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
    template <typename A, typename B>istream& operator>>(istream& input,pair<A,B>& x) {input>>x.F>>x.S;return input;}
    template <typename A>istream& operator>>(istream& input,vector<A>& x) {for(auto& i:x)	input>>i;return input;}
    template<typename A>ostream& operator<<(ostream& output,vector<A>& x) {for(auto& i:x)	output<<i<<' ';	return output;}
    void add(int&,int );
    int sub(int ,int );
    int mul(int,int);
    int powz(int ,int );
    ll binpow(int , int );
    int gcd(int ,int);
    bool sortinrev(const pair<char,int>a,pair<char,int>b){ return (a.S<b.S);}
    bool Compdoub( double a , double b ) { if((a-b)<e)return 1; else return 0; }
    template < typename T> void smax(T& a , T b){ a = max(a,b); }
    template < typename T> void smin(T& a , T b){ a = min(a,b); }
    /***************************************************main code**************************************************************/
    const int N=1e6+5;
    const int inf = 1e9+100;
    int msg(string s)
    {
		int pos = s.find(':');
		int len = sz(s) - pos-1;
		//~ debug(s);
		//~ string str = s.substr(pos+1);
		//~ debug(str);
		//~ debug(len);
		return len;
	}

    void solve()
    {
		string s[101];

		set<string>st;
		int tot_msg = 0;

		for(int i = 0 ; i < 100 ; ++i)
		{
			getline(cin,s[i]);
			if(s[i][0] == '+')
			{

				string str = s[i].substr(1);
				//~ debug(str);
				st.insert(str);

			}
			else if(s[i][0] == '-')
			{
				string str = s[i].substr(1);
				//~ debug(str);
				st.erase(str);
			}
			else
			{
				//~ debug(s[i]);
				int n = sz(st);
				tot_msg += n*msg(s[i]);
			}
		}

		cout <<tot_msg;

    }
    /*************----------------------------******************/
    signed main(){
    	ios_base::sync_with_stdio(false);
    	cin.tie(0);
    	int tc=1;
    	//~ cin>>tc;
    	for(int _=0;_<tc;_++){
    		//~ cout<<"Case #"<<_+1<<": ";
    		solve();
    		if(_!=tc-1)
    		cout<<"\n";
    	}

    }
    ll binpow(int a, int b)
     {    ll res = 1;
    	 while (b > 0){
    		 if(b & 1)res = res*a;
    		  a = a *1ll*a;
    		   b >>= 1;
    	  }
       return res;
     }
    int powz(int a,int b)
    {
    	int res=1;
    	while(b)
    	{
    		if(b&1)res=mul(res,a);
    		b/=2;
    		a=mul(a,a);
    	}
    	return res;
    }
    int gcd(int a ,int b){
    	if(b ==0)return a;
    	return gcd(b,a%b);
    }
    int sub(int a,int b){
    	a-=b;
    	if(a<0){
    		a+=mod;
    	}
    	return a;
    }
    int mul(int a,int b)
    {
    	return ((a)*1ll*(b))%mod;
    }
    void add(int &a,int b)
    {
    	a+=b;
    	if(a>=mod)a-=mod;
    }


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n=0,rez=0,i,m;
    string aux;
    while(getline(cin,aux))
    {
        if (aux[0]=='+') n++;
        else if(aux[0]=='-') n--;
        else
        {
            i = 0;
            while (aux[i]!=':')
            {
                i++;
            }
            rez=rez+n*(aux.length()-i-1);
        }
        //cout<<n<<' '<<rez<<'\n';
    }
    cout<<rez;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n=0,rez=0,i,m;
    string aux;
    while(getline(cin,aux))
    {
        if (aux[0]=='+') n++;
        else if(aux[0]=='-') n--;
        else
        {
            i = 0;
            while (aux[i]!=':')
            {
                i++;
            }
            rez=rez+n*(aux.length()-i-1);
        }
        //cout<<n<<' '<<rez<<'\n';
    }
    cout<<rez;
    return 0;
    //aa1
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n=0,rez=0,i,m;
    string aux;
    while(getline(cin,aux))
    {
        if (aux[0]=='+') n++;
        else if(aux[0]=='-') n--;
        else
        {
            i = 0;
            while (aux[i]!=':')
            {
                i++;
            }
            rez=rez+n*(aux.length()-i-1);
        }
        //cout<<n<<' '<<rez<<'\n';
    }
    cout<<rez;
    return 0;
    //aaa
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    string a;
    int y,k=0,j,k1,r=0;
    while(cin>>a)
    {
        y=a.length();
        if(a[0]=='+')
        {
            k++;
        }
        else if(a[0]=='-')
        {
            k--;
        }
        else
        {
            j=0;
            k1=0;
            for(int i=1;i<y;i++)
            {
                if(a[i]==':')
                {
                    j=1;
                }
                else if(j==1)
                {
                    k1++;
                }
            }
            r=r+k1*k;
        }
    }
    cout<<r;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    string a;
    int y,k=0,j,k1,r=0;
    while(getline(cin,a))
    {
        y=a.length();
        if(a[0]=='+')
        {
            k++;
        }
        else if(a[0]=='-')
        {
            k--;
        }
        else
        {
            j=0;
            k1=0;
            for(int i=1;i<y;i++)
            {
                if(a[i]==':')
                {
                    j=1;
                }
                else if(j==1)
                {
                    k1++;
                }
            }
            r=r+k1*k;
        }
    }
    cout<<r;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    string a;
    int y,k=0,j,k1,r=0;
    do
    {
        cin>>a;
        y=a.length();
        if(a[0]=='+')
        {
            k++;
        }
        else if(a[0]=='-')
        {
            k--;
        }
        else
        {
            j=0;
            k1=0;
            for(int i=1;i<y;i++)
            {
                if(a[i]==':')
                {
                    j=1;
                }
                else if(j==1)
                {
                    k1++;
                }
            }
            r=r+k1*k;
        }
    }while(1);
    cout<<r;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    string a;
    int y,k=0,j,k1,r=0;
    for(;getline(cin,a);)
    {
        y=a.length();
        if(a[0]=='+')
        {
            k++;
        }
        else if(a[0]=='-')
        {
            k--;
        }
        else
        {
            j=0;
            k1=0;
            for(int i=1;i<y;i++)
            {
                if(a[i]==':')
                {
                    j=1;
                }
                else if(j==1)
                {
                    k1++;
                }
            }
            r=r+k1*k;
        }
    }
    cout<<r;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    string a;
    int y,k=0,j,k1,r=0;
    while(cin>>a)
    {
        y=a.length();
        if(a[0]=='+')
        {
            k++;
        }
        else if(a[0]=='-')
        {
            k--;
        }
        else
        {
            j=0;
            k1=0;
            for(int i=1;i<y;i++)
            {
                if(a[i]==':')
                {
                    j=1;
                }
                else if(j==1)
                {
                    k1++;
                }
            }
            r=r+k1*k;
        }
    };
    cout<<r;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
	int count = 0, sum = 0, a;
	string str;
	while (getline(cin, str)){
		if (str[0] == '+')
			count++;
		else if (str[0] == '-')
			count--;
		else {
			a = str.find(':') + 1;
			sum += (str.size() - a)*count;
		}
	}
	cout << sum;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
	int count = 0, sum = 0, a;
	string str;
	while (getline(cin, str)){
		if (str[0] == '+')
			count++;
		else if (str[0] == '-')
			count--;
		else {
			a = str.find(':') - 1;
			sum += (str.size() - a)*count;
		}
	}
	cout << sum;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
	int count = 0, sum = 0, a = 0;
	string str;
	while (getline(cin, str)){
		if (str[0] == '+')
			count++;
		else if (str[0] == '-')
			count--;
		else {
			for (; str[a] != ':'; a++);
			sum += (str.size() - a - 1)*count;
		}
	}
	cout << sum;
}


#include<bits/stdc++.h>
using namespace std;
const int maxn = 105;
string a;
int main(void) {

    int ansn = 0, ans = 0;
    while(getline(cin, a)) {

      if(a[0] == '+') ansn++;
      if(a[0] == '-') ansn--;
      else for(int i = 0; i < a.size(); i++) if(a[i] == ':') ans += ansn * (a.size() - i - 1);
    }
    cout << ans;

}


#include<bits/stdc++.h>
using namespace std;
const int maxn = 105;
char a[maxn];
int main(void) {

    int ansn = 0, ans = 0;
    while(cin.getline(a, 105, '\n')) {

      if(a[0] == '+') ansn++;
      if(a[0] == '-') ansn--;
      else for(int i = 0; i < strlen(a); i++) if(a[i] == ':') ans += ansn * (strlen(a) - i - 1);
    }
    cout << ans;

}


#include<bits/stdc++.h>
using namespace std;
const int maxn = 105;
string a;
int main(void) {

    int ansn = 0, ans = 0;
    while(getline(cin, a)) {

      if(a[0] == '+') ansn++;
      else if(a[0] == '-') ansn--;
      else ans += (a.size() - a.find(':') - 1) * ansn;
    }
    cout << ans;

}


#pragma warning(disable:4786)
#pragma warning(disable:4996)
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/trie_policy.hpp>
#include<ext/pb_ds/detail/standard_policies.hpp>
#define pii pair<int,int>
#define pll pair<long long ,long long>
#define pli pair<long long , int>
#define pil pair<int ,long long>
#define pi acos(-1)
#define pb push_back
#define mkp make_pair
#define all(a) a.begin(), a.end()
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long
#define MAX 300005
#define INF 0x3f3f3f3f
template <class T> inline T bigmod(T p,T e,T M){ll ret = 1LL;for(; e > 0LL; e >>= 1LL){if(e & 1LL) ret = (ret * p) % M;p = (p * p) % M;}return (T)ret;}
template <class T> inline T modinverse(T a,T M){return bigmod(a,M-2,M);}   // M is prime}

using namespace std;
using namespace __gnu_pbds;

typedef trie<string,null_type,trie_string_access_traits<>,pat_trie_tag,trie_prefix_search_node_update>pref_trie;
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;

int main(){
    //IOS
    //freopen("output.txt","w",stdout);
    string s;
    set<string>st;
    int ans =0;
    char c;
    while(scanf("%c",&c)!=EOF){
        getline(cin,s);
        getchar();
        if(c=='+'){
            string str(s.begin()+1,s.end());
            st.insert(str);
        }
        else if(c=='-'){
            string str(s.begin()+1,s.end());
            st.erase(str);
        }
        else{
            int idx;
            for(int i=0;i<s.length();i++){
                if(s[i]==':'){
                    idx=i;
                    break;
                }
            }

            ans+= (s.length()-idx-1)*st.size();
        }
        //cout<<ans<<endl;
    }
    cout<<ans;
}


#pragma warning(disable:4786)
#pragma warning(disable:4996)
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/trie_policy.hpp>
#include<ext/pb_ds/detail/standard_policies.hpp>
#define pii pair<int,int>
#define pll pair<long long ,long long>
#define pli pair<long long , int>
#define pil pair<int ,long long>
#define pi acos(-1)
#define pb push_back
#define mkp make_pair
#define all(a) a.begin(), a.end()
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long
#define MAX 300005
#define INF 0x3f3f3f3f
template <class T> inline T bigmod(T p,T e,T M){ll ret = 1LL;for(; e > 0LL; e >>= 1LL){if(e & 1LL) ret = (ret * p) % M;p = (p * p) % M;}return (T)ret;}
template <class T> inline T modinverse(T a,T M){return bigmod(a,M-2,M);}   // M is prime}

using namespace std;
using namespace __gnu_pbds;

typedef trie<string,null_type,trie_string_access_traits<>,pat_trie_tag,trie_prefix_search_node_update>pref_trie;
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;

int main(){
    //IOS
    //freopen("output.txt","w",stdout);
    string s;
    set<string>st;
    int ans =0;
    char c;
    while(cin>>c){
        getline(cin,s);
        if(c=='+'){
            string str(s.begin()+1,s.end());
            st.insert(str);
        }
        else if(c=='-'){
            string str(s.begin()+1,s.end());
            st.erase(str);
        }
        else{
            int idx;
            for(int i=0;i<s.length();i++){
                if(s[i]==':'){
                    idx=i;
                    break;
                }
            }

            ans+= (s.length()-idx-1)*st.size();
        }
        //cout<<ans<<endl;
    }
    cout<<ans;
}


#pragma warning(disable:4786)
#pragma warning(disable:4996)
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/trie_policy.hpp>
#include<ext/pb_ds/detail/standard_policies.hpp>
#define pii pair<int,int>
#define pll pair<long long ,long long>
#define pli pair<long long , int>
#define pil pair<int ,long long>
#define pi acos(-1)
#define pb push_back
#define mkp make_pair
#define all(a) a.begin(), a.end()
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long
#define MAX 300005
#define INF 0x3f3f3f3f
template <class T> inline T bigmod(T p,T e,T M){ll ret = 1LL;for(; e > 0LL; e >>= 1LL){if(e & 1LL) ret = (ret * p) % M;p = (p * p) % M;}return (T)ret;}
template <class T> inline T modinverse(T a,T M){return bigmod(a,M-2,M);}   // M is prime}

using namespace std;
using namespace __gnu_pbds;

typedef trie<string,null_type,trie_string_access_traits<>,pat_trie_tag,trie_prefix_search_node_update>pref_trie;
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;

int main(){
    //IOS
    //freopen("output.txt","w",stdout);
    string s;
    set<string>st;
    int ans =0;
    char c;
    while(getline(cin,s)){

        if(s[0]=='+'){
            string str(s.begin()+1,s.end());
            st.insert(str);
        }
        else if(s[0]=='-'){
            string str(s.begin()+1,s.end());
            st.erase(str);
        }
        else{
            int idx;
            for(int i=0;i<s.length();i++){
                if(s[i]==':'){
                    idx=i;
                    break;
                }
            }

            ans+= (s.length()-idx-1)*st.size();
        }
        //cout<<ans<<endl;
    }
    cout<<ans;
}


#pragma warning(disable:4786)
#pragma warning(disable:4996)
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/trie_policy.hpp>
#include<ext/pb_ds/detail/standard_policies.hpp>
#define pii pair<int,int>
#define pll pair<long long ,long long>
#define pli pair<long long , int>
#define pil pair<int ,long long>
#define pi acos(-1)
#define pb push_back
#define mkp make_pair
#define all(a) a.begin(), a.end()
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long
#define MAX 300005
#define INF 0x3f3f3f3f
template <class T> inline T bigmod(T p,T e,T M){ll ret = 1LL;for(; e > 0LL; e >>= 1LL){if(e & 1LL) ret = (ret * p) % M;p = (p * p) % M;}return (T)ret;}
template <class T> inline T modinverse(T a,T M){return bigmod(a,M-2,M);}   // M is prime}

using namespace std;
using namespace __gnu_pbds;

typedef trie<string,null_type,trie_string_access_traits<>,pat_trie_tag,trie_prefix_search_node_update>pref_trie;
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;

int main(){
    //IOS
    //freopen("output.txt","w",stdout);
    string s;
    set<string>st;
    int ans =0;
    char c;
    while(scanf("%c",&c)!=EOF){
        getline(cin,s);

        if(c=='+'){
            string str(s.begin()+1,s.end());
            st.insert(str);
        }
        else if(c=='-'){
            string str(s.begin()+1,s.end());
            st.erase(str);
        }
        else{
            int idx;
            for(int i=0;i<s.length();i++){
                if(s[i]==':'){
                    idx=i;
                    break;
                }
            }

            ans+= (s.length()-idx-1)*st.size();
        }
        //cout<<ans<<endl;
    }
    cout<<ans;
}


#pragma warning(disable:4786)
#pragma warning(disable:4996)
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/trie_policy.hpp>
#include<ext/pb_ds/detail/standard_policies.hpp>
#define pii pair<int,int>
#define pll pair<long long ,long long>
#define pli pair<long long , int>
#define pil pair<int ,long long>
#define pi acos(-1)
#define pb push_back
#define mkp make_pair
#define all(a) a.begin(), a.end()
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long
#define MAX 300005
#define INF 0x3f3f3f3f
template <class T> inline T bigmod(T p,T e,T M){ll ret = 1LL;for(; e > 0LL; e >>= 1LL){if(e & 1LL) ret = (ret * p) % M;p = (p * p) % M;}return (T)ret;}
template <class T> inline T modinverse(T a,T M){return bigmod(a,M-2,M);}   // M is prime}

using namespace std;
using namespace __gnu_pbds;

typedef trie<string,null_type,trie_string_access_traits<>,pat_trie_tag,trie_prefix_search_node_update>pref_trie;
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;

int main(){
    //IOS
    //freopen("output.txt","w",stdout);
    string s;
    set<string>st;
    int ans =0;
    char c;
    while(scanf("%c",&c)!=EOF){
        getline(cin,s);
        if(s=="0")break;
        if(c=='+'){
            string str(s.begin()+1,s.end());
            st.insert(str);
        }
        else if(c=='-'){
            string str(s.begin()+1,s.end());
            st.erase(str);
        }
        else{
            int idx;
            for(int i=0;i<s.length();i++){
                if(s[i]==':'){
                    idx=i;
                    break;
                }
            }

            ans+= (s.length()-idx-1)*st.size();
        }
        //cout<<ans<<endl;
    }
    cout<<ans;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
        string s;
        int p=0,ans=0,x,i, index=0;
        char c;
        while(scanf("%c",&c)!=EOF){
            getline(cin,s);
            if(c=='+')
                p++;
            else if(c=='-')
                p--;
            else{
                for(i=0;i<=s.length();i++){
                    if(s[i]==':'){
						index=i+1;
                        break;
                    }
                }
                ans+=((s.length()-index)*p);
            }
        }
        cout<<ans;
        return 0;

}


#include <iostream>
#include<string>
using namespace std;
int main() {
  int ans=0;
  string dummy;
  getline(cin, dummy);
  while(!cin.eof()){
	string a;
	getline(cin, a);
	if(a[0]=='-' or a[0]=='+')
	continue;
	int x=a.length();
	int index=0;
	for(int i=0;i<x-1;i++){
		if(a[i]==':'){
			index=i+1;
			break;
		}
	}
	//cout<<index<<" "<<a.length()<<endl;
	ans+=a.length()-(index);
  }
  cout<<ans<<endl;
}


#include<iostream>
#include<cmath>
#include<algorithm>
using namespace std;
int main()
{
	string s;
	int curppl=0, ans=0, x, index=0;
	char c;
	while(!cin.eof()){
		cin>>c;
		getline(cin,s);
		if(c=='+')
			curppl++;
		else if(c=='-')
			curppl--;
		else{
			for(int i=0;i<=s.length();i++){
				if(s[i]==':'){
					index=i+1;
					break;
				}
			}
			ans+=((s.length()-index)*curppl);
		}
	}
	cout<<ans;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
ifstream fin("bac.in");

int main()
{
    //ios_base::sync_with_stdio(0);
    //cin.tie(0);
    vector<string> v;

    int suma=0;
    int n = 0;

   for(int i=1; i<=7; i++)
    {
        string s;
        int nr=0;

        getline(cin,s);

        if(isupper(s[0]))
        {
            int j = 0;

            while(s[j]!=':')
            {
                ++j;
            }

            for(int k=j+1; k<s.size(); k++)
            {
                nr++;
            }
            suma+=nr*n;

        }

        if(s[0]=='+')
        {
            ++n;
        }

        else if(s[0]=='-')
        {
            --n;
        }

    }
    cout<<suma;

}


#include<bits/stdc++.h>
using namespace std;
ifstream fin("bac.in");

int main()
{
    //ios_base::sync_with_stdio(0);
    //cin.tie(0);
    vector<string> v;

    int suma=0;
    int n = 0;

    string s;

    while(getline(cin,s))
    {

        int nr=0;

        if((s[0])!='-' && s[0]!='+')
        {
            int j = 0;

            while(s[j]!=':')
            {
                ++j;
            }

            for(int k=j+1; k<s.size(); k++)
            {
                nr++;
            }
            suma+=nr*n;

        }

        if(s[0]=='+')
        {
            ++n;
        }

        else if(s[0]=='-')
        {
            --n;
        }

    }
    cout<<suma;

}


#include<bits/stdc++.h>
using namespace std;
ifstream fin("bac.in");

int main()
{
    //ios_base::sync_with_stdio(0);
    //cin.tie(0);
    vector<string> v;

    int suma=0;
    int n = 0;

    string s;

    while(getline(cin,s))
    {

        int nr=0;

        if(isupper(s[0]))
        {
            int j = 0;

            while(s[j]!=':')
            {
                ++j;
            }

            for(int k=j+1; k<s.size(); k++)
            {
                nr++;
            }
            suma+=nr*n;

        }

        if(s[0]=='+')
        {
            ++n;
        }

        else if(s[0]=='-')
        {
            --n;
        }

    }
    cout<<suma;

}


#define debug cout<<"working 1 "<<endl;
#define ll long long
#define pb push_back
#define mp make_pair

#include<bits/stdc++.h>
using namespace std;
int main() {
	string s;
	set<string> se;
	int cnt = 0;

	while (getline(cin, s)) {

		if (s[0] == '+') {
			se.insert(s);

			continue;
		}

		if (s[0] == '-' && se.find(s) != se.end()) {
			set<string>::iterator itr=se.find(s);
			se.erase(itr);

			continue;
		}
		int pos = 0;
		for (int i = 0; i < s.size(); i++) {
			if (s[i] == ':') {
				pos = i; break;
			}
		}

		cnt = cnt + se.size() * (s.size() - (pos + 1));

	}
	cout << cnt<<endl;
	return 0;

}


#define debug cout<<"working 1 "<<endl;
#define ll long long
#define pb push_back
#define mp make_pair

#include<bits/stdc++.h>
using namespace std;
int main() {
	string s;
	set<string> se;
	int cnt = 0;

	while (getline(cin, s)) {
		string ns=s.substr(1);
			se.insert(ns);

		if (s[0] == '+') {

			se.insert(ns);

			continue;
		}

		if (s[0] == '-' && se.find(ns) != se.end()) {
			set<string>::iterator itr=se.find(ns);
			se.erase(itr);

			continue;
		}
		int pos = 0;
		for (int i = 0; i < s.size(); i++) {
			if (s[i] == ':') {
				pos = i; break;
			}
		}

		cnt = cnt + se.size() * (s.size() - (pos + 1));

	}

	cout << cnt<<endl;
	return 0;

}


/******************************************************************************

                              Online C++ Compiler.
               Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

#define debug cout<<"working 1 "<<endl;
#define ll long long
#define pb push_back
#define mp make_pair

#include<bits/stdc++.h>
using namespace std;
int main() {
	string s;

	set<string> se;
	int cnt = 0;

	while (getline(cin, s)) {
		string ns=s.substr(1);

		if (s[0] == '+') {

			se.insert(ns);

			continue;
		}

		if (s[0] == '-' && se.find(ns) != se.end()) {
			auto itr=se.find(ns);
			se.erase(itr);

			continue;
		}
		int pos = 0;
		for (int i = 0; i < s.size(); i++) {
			if (s[i] == ':') {
				pos = i; break;
			}
		}

		cnt = cnt + se.size() * (s.size() - (pos + 1));

	}

	cout << cnt<<endl;
	return 0;

}


#include <bits/stdc++.h>
//in the name of god;;
using namespace std;
typedef long long ll;
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
  ll ans, ans2;
 int main()
 {
 	string ss="";
	for(;getline(cin, ss);){
		if(ss.size() == 0)break;
		if(ss[0] == '+')++ans;
		else if(ss[0] == '-')--ans;
		else{
			ll rt = 1;
			for(int j = 0; ss[j] != ':'; ++j)++rt;
			ans2 += ((ss.size() - rt) * ans);
		}
	}
	cout << ans2;
	return 0;
 }


#include <bits/stdc++.h>
//in the name of god;;
using namespace std;
typedef long long ll;
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
  string st[8];
  ll ans, ans2;
 int main()
 {
 	for(ll i = 0; i < 7; ++i)getline(cin, st[i]);
	for(ll i = 0; i < 7; ++i){
		if(st[i][0] == '+')++ans;
		else if(st[i][0] == '-')--ans;
		else{
			ll rt = 1;
			for(ll j = 0; st[i][j] != ':'; ++j)++rt;
			ans2 += ((st[i].size() - rt) * ans);
		}
	}
	cout << ans2;
 }


#include<bits/stdc++.h>

using namespace std;

#define ff				first
#define ss				second
#define int				long long
#define pb				push_back
#define mp				make_pair
#define pii				pair<int,int>
#define vi				vector<int>
#define mii 			map<int,int>
#define	pqb				priority_queue<int>
#define pqs				priority_queue<int,vi,greater<int> >
#define setbits(x)		__builtin_popcountll(x)
#define zrobits(x)		__builtin_ctzll(x)
#define mod				1000000009
#define inf 			1e18
#define ps(x,y)			fixed<<setprecision(y)<<x
#define mk(arr,n,type)	type *arr = new type[n]
#define w(x)			int x; cin>>x; while(x--)
#define FIO             ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define endl			'\n'
#define yes cout<<"YES"<<endl
#define no cout<<"NO"<<endl

const int maxn = 1e5 + 5;
void c_p_c()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

}

bool isPrime(int n)
{
	if (n <= 1)
		return false;
	if (n <= 3)
		return true;
	if (n % 2 == 0 || n % 3 == 0)
		return false;
	for (int i = 5; i * i <= n; i += 6)
	{
		if (n % i == 0 || n % (i + 2) == 0)
			return false;

	}
	return true;
}

vector<int> Sieve(int n)
{
	bool prime[n + 1];
	memset(prime, true, sizeof(prime));
	for (int i = 2; i * i <= n; i++)
	{
		if (prime[i])
		{
			for (int j = i * i; j <= n; j += i)
			{
				prime[j] = false;
			}
		}
	}
	vector<int> primes;

	for (int i = 2; i <= n; i++)
	{
		if (prime[i])
			primes.pb(i);
	}
	return primes;
}
set<int> primeFactors(int  n)
{
	set<int> factors;
	while (n % 2 == 0)
	{
		n /= 2;
		factors.insert(2);

	}
	for (int i = 3; i <= sqrt(n); i += 2)
	{
		// int count = 0;
		while (n % i == 0)
		{
			factors.insert(i);
			n /= i;
		}
	}
	if (n > 2)
		factors.insert(n);
	return factors;
}

int power(int x, unsigned int y, int p)
{
	int res = 1;

	x = x % p;

	if (x == 0) return 0;
	;
	while (y > 0)
	{

		if (y & 1)
			res = (res * x) % p;

		y = y >> 1; // y = y/2
		x = (x * x) % p;
	}
	return res;

}

// Graph------------------------------------------------------------------------

int32_t main()
{
	// FIO;
	c_p_c();
	// --------------------------------------------------
	// Never GIVE UP !!!!
	int numPeople = 0;
	char c;
	string s;
	int traffic = 0;
	while (getline(cin, s))
	{
		if (s[0] == '+')
		{
			numPeople++;
		}
		else if (s[0] == '-')
			numPeople--;
		else
		{
			int t = s.find(':');
			traffic = traffic + (s.length() - t - 1) * numPeople;
		}
	}
	cout << traffic << endl;
}


#include<bits/stdc++.h>

using namespace std;

#define ff				first
#define ss				second
#define int				long long
#define pb				push_back
#define mp				make_pair
#define pii				pair<int,int>
#define vi				vector<int>
#define mii 			map<int,int>
#define	pqb				priority_queue<int>
#define pqs				priority_queue<int,vi,greater<int> >
#define setbits(x)		__builtin_popcountll(x)
#define zrobits(x)		__builtin_ctzll(x)
#define mod				1000000007
#define inf 			1e18
#define ps(x,y)			fixed<<setprecision(y)<<x
#define mk(arr,n,type)	type *arr = new type[n]
#define w(x)			int x; cin>>x; while(x--)
#define FIO             ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)

void c_p_c()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

}

bool isPrime(int n)
{
	if (n <= 1)
		return false;
	if (n <= 3)
		return true;
	if (n % 2 == 0 || n % 3 == 0)
		return false;
	for (int i = 5; i * i <= n; i += 6)
	{
		if (n % i == 0 || n % (i + 2) == 0)
			return false;

	}
	return true;

}

bool cmp(pii a, pii b)
{
	return abs(a.ff - a.ss) <= abs(b.ff - b.ss);
}

int32_t main()
{
	// FIO;
	c_p_c();
	string s;
	int num = 0;
	int ans = 0;
	while (getline(cin, s))
	{
		if (s[0] == '+')
			num++;
		else if ( s[0] == '-')
			num--;
		else
		{
			int i;
			for ( i = 0; i < s.length(); i++)
			{
				if (s[i] == ':')
					break;
			}
			ans += (s.length() - 1 - i) * (num);
		}
	}
	cout << ans << endl;

}


#include <bits/stdc++.h>
#define IOS ios_base::sync_with_stdio(false); cin.tie(0);
#define sz(s) (int)s.size()
using namespace std;

int main(){
    IOS;
    string s;
    unordered_set<string> st;
    int ans = 0;
    while(getline(cin, s)){
        if(s[0] == '+')
            st.insert(s.substr(1, sz(s)-1));
        else if(s[0] == '-')
            st.erase(s.substr(1, sz(s)-1));
        else{
            bool flag = false;
            int len = 0;
            for(int i=0; i<sz(s); i++){
                if(flag) len++;
                if(s[i] == ':') flag = true;
            }
            ans += len * st.size();
        }
    }
    cout << ans;
    return 0;
}


#include <bits/stdc++.h>
#define IOS ios_base::sync_with_stdio(false); cin.tie(0);
#define sz(s) (int)s.size()
using namespace std;

int main(){
    IOS;
    string s;
    unordered_set<string> st;
    int ans = 0;
    while(cin >> s){
        if(s[0] == '+')
            st.insert(s.substr(1, sz(s)-1));
        else if(s[0] == '-')
            st.erase(s.substr(1, sz(s)-1));
        else{
            bool flag = false;
            int len = 0;
            for(int i=0; i<sz(s); i++){
                if(flag) len++;
                if(s[i] == ':') flag = true;
            }
            ans += len * st.size();
        }
    }
    cout << ans;
    return 0;
}


#include <bits/stdc++.h>
#define IOS ios_base::sync_with_stdio(false); cin.tie(0);
using namespace std;

string s;
int ans, num;

int main(){
    IOS;
    while(getline(cin, s)){
        if(s[0] == '+') num++;
        else if(s[0] == '-') num--;
        else ans += num * (s.size()-s.find(':')-1);
    }
    cout << ans;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
char s[200];
set<string> lst;
int ans;
int main()
{
    ios::sync_with_stdio(false);
    while( !cin.eof() )
    {
        cin.getline(s, 100);
        string t = s;
        if( t[0] == '+' ) lst.insert(t.substr(1,t.size()-1));
        else if( t[0] == '-' ) lst.erase(t.substr(1,t.size()-1));
        else
        {
            int c = 0;
            while( t[c] != ':' ) c++;
            ans += (t.size()-c-1)*lst.size();
        }
        cout<<ans<<" "<<lst.size()<<endl;
    }
    cout<<ans;
}


#include <bits/stdc++.h>
using namespace std;
char s[200];
set<string> lst;
int ans;
int main()
{
    ios::sync_with_stdio(false);
    while( !cin.eof() )
    {
        cin.getline(s, 100);
        string t = s;
        if( t[0] == '+' ) lst.insert(t.substr(1,t.size()-1));
        else if( t[0] == '-' ) lst.erase(t.substr(1,t.size()-1));
        else
        {
            int c = 0;
            while( t[c] != ':' ) c++;
            ans += (t.size()-c-1)*lst.size();
        }
    }
    cout<<ans;
}


#include <bits/stdc++.h>
using namespace std;
char s[200];
set<string> lst;
int ans;
int main()
{
    ios::sync_with_stdio(false);
    int x = 10;
    while( x-- )
    {
        cin.getline(s, 110);
        string t = s;
        if( t.size() < 2 ) continue;
        if( t[0] == '+' ) lst.insert(t.substr(1,t.size()-1));
        else if( t[0] == '-' ) lst.erase(t.substr(1,t.size()-1));
        else
        {
            int c = 0;
            while( t[c] != ':' ) c++;
            ans += (t.size()-c-1)*lst.size();
        }
    }
    cout<<ans;
}


#include <bits/stdc++.h>
using namespace std;
char s[200];
set<string> lst;
int ans;
int main()
{
    ios::sync_with_stdio(false);
    int x = 10;
    while( cin.getline(s, 110) )
    {
        string t = s;
        if( t.size() < 2 ) continue;
        if( t[0] == '+' ) lst.insert(t.substr(1,t.size()-1));
        else if( t[0] == '-' ) lst.erase(t.substr(1,t.size()-1));
        else
        {
            int c = 0;
            while( t[c] != ':' ) c++;
            ans += (t.size()-c-1)*lst.size();
        }
    }
    cout<<ans;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
        string s;
        int p=0,l=0,x,i;
        char ch;

        while(scanf("%c",&ch)!=EOF)
        {
            getline(cin,s);
            if(ch=='+')
                p++;
            else if(ch=='-')
                p--;
            else
            {
                for(i=0;i<=s.length();i++)
                {
                    if(s[i]==':')
                    {
                        break;
                    }
                }

                l+=((s.length()-i-1)*p);
            }
        }

        cout<<l;

        return 0;

}


#include <stdio.h>
#include <string.h>
int main(){

	char a[105];
	int trf=0;
	int x=0;
	int temp;
	int i;
	char ch;
	while(scanf("%c", &ch)!=EOF){
		scanf("%[^\n]", a);
		if(ch=='+'){
			trf++;
		}
		else if(ch=='-'){
			trf--;
		}
		else{
			temp=strlen(a);
			for(i=0; i<temp; i++){
				if(a[i]==':'){
					break;
				}
			}
			x+=((temp-i)*trf);
		}
	}
	printf("%d\n", x);

	return 0;
}


#include <iostream>
#include <list>
using namespace std;

int main(){
    string s;
    int t=0,h=0,r=0;
    for (int i=0;i<7;i++){
        getline(cin,s);
        if (s[0]=='+'|| s[0]=='-'){
            if (s[0]=='-'){
                t--;
            }
            else{
                t++;
            }
        }
        else{
            while(s[r]!=':'){
                r++;
            }
            for (int i=r+1;i<s.length();i++){
                h+=t;
            }
        }

    }

    cout << h;

}


#include<iostream>
#include<vector>
#include<map>
#include<numeric>
#include<algorithm>
#define int long long
using namespace std;

int cnt, n;
char com[100000];

int32_t main()
{
	cnt = 0;
	n = 0;
	while(gets(com))
	{
		if(com[0] == '+')//add in char
		{
			n++;
		}
		else if(com[0] == '-')//remove from chat
		{
			n--;
		}
		else
		{
			int len = strlen(com), p = 0;
			while(com[p] != ':') p++;//count how many letters are before :

			cnt += n * (len - 1 - p);//calculate traffic sent to persons that are in chat
		}
	}
	cout << cnt << '\n';

	return 0;
}


#include<iostream>
#include<vector>
#include<map>
#include<numeric>
#include<algorithm>
#include<cstring>
#define int long long
using namespace std;

int cnt, n;
char com[100000];

int32_t main()
{
	cnt = 0;
	n = 0;
	while(gets(com))
	{
		if(com[0] == '+')//add in char
		{
			n++;
		}
		else if(com[0] == '-')//remove from chat
		{
			n--;
		}
		else
		{
			int len = strlen(com), p = 0;
			while(com[p] != ':') p++;//count how many letters are before :

			cnt += n * (len - 1 - p);//calculate traffic sent to persons that are in chat
		}
	}
	cout << cnt << '\n';

	return 0;
}


#include <bits/stdc++.h>
using namespace std;
void fast(){
cin.tie(0);
cin.sync_with_stdio(0);
}
int min_d(int a[ ],int i,int j)
{
    if (i>=j) return 0;
    else if(a[i]==a[j]){return min_d(a,i+1,j-1);}
    else return 1+min( min_d(a,i+1,j), min_d(a,i,j-1));
}
int main()
{
    fast();
    string s;long long su=0;long long n=0;
    while(1)
    {
        try{
            getline(cin,s);
            if(s.size()==0) throw 1;
            }
        catch(int a) { break;}

       if(s[0]=='+') {n++;}
       else if(s[0]=='-') {n--;}
       else {
        string ss=s.substr(s.find(':')+1);
        su+=n * (ss.size()-count(ss.begin(),ss.end(),' '));
       }
    }
    cout<<su;
return 0;
}


#include <bits/stdc++.h>
using namespace std;
void fast(){
cin.tie(0);
cin.sync_with_stdio(0);
}
int min_d(int a[ ],int i,int j)
{
    if (i>=j) return 0;
    else if(a[i]==a[j]){return min_d(a,i+1,j-1);}
    else return 1+min( min_d(a,i+1,j), min_d(a,i,j-1));
}
int main()
{
    fast();
    string s;long long su=0;long long n=0;
    while(getline(cin,s))
    {
    if(s==""){break;}
       if(s[0]=='+') {n++;}
       else if(s[0]=='-') {n--;}
       else {
        string ss=s.substr(s.find(':')+1);
        su+=n * (ss.size());
       }
    }
    cout<<su;
return 0;
}


#include<bits/stdc++.h>
using namespace std;
void fast()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
}
int main()
{
       fast();
       string s;
       int count=0,ans=0;
       getline(cin, s);
       while ( s.size() != 0 )
       {
           int sum=0,p=0;
           if(s[0]=='+')
               {
                   count++;
               }
           else if(s[0]=='-')
               {
                   count -- ;
               }
            else
            {
                    sum=s.size();
                    for(int i=0;s[i];i++)
                    {
                        if(s[i]==':')
                        {
                            p++;
                            break;
                        }
                        else
                            p++;
                    }
                    sum=sum-p;
                    ans+=sum*count;

            }
            getline(cin, s);
       }
       cout<<ans<<endl;
}


#include<bits/stdc++.h>
using namespace std;
void fast()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
}
int main()
{
       fast();
       string s;
       int count=0,ans=0;
       while (getline(cin, s))
       {
           int sum=0,p=0;
           if(s[0]==' + ')
               {
                   count++;
                   continue;
               }
           else if(s[0]==' - ')
               {
                   count -- ;
                   continue;
               }
            sum=s.size();
            for(int i=0;s[i];i++)
            {
                if(s[i]==':')
                {
                    p++;
                    break;
                }
                else
                    p++;
            }
            sum=s.size()-p;
            ans+=sum*count;
       }
       cout<<ans<<endl;
}


#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define ld long double
#define pb push_back
#define qwerty1 first
#define qwerty2 second
#define qwerty3 -> first
#define qwerty4 -> second
#define umap unordered_map
#define uset unordered_set
#define pii pair < int , int >
#define pq priority_queue

using namespace std;

const int N = 100005;
const int M = 1000000007;
const ld PI = acos(-1);

ll t = 1;
string command;

void Test()
{
    ll pers = 0 , traffic = 0;

    while(getline(cin , command))
    {

        if(!isalpha(command[0]))
        {
            if(command[0] == '+')
                ++pers;
            else --pers;
        }
        else traffic += command.substr( command.find(':') + 1 , string::npos ).size() * pers;
    }

    cout << traffic;
}

int main()
{
	#ifndef ONLINE_JUDGE
    freopen("in" , "r" , stdin) , freopen("out" , "w" , stdout);
    #endif

    ios_base::sync_with_stdio(false) , cin.tie(0) , cout.tie(0);

	while(t--)
		Test();

    return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define ld long double
#define pb push_back
#define qwerty1 first
#define qwerty2 second
#define qwerty3 -> first
#define qwerty4 -> second
#define umap unordered_map
#define uset unordered_set
#define pii pair < int , int >
#define pq priority_queue

using namespace std;

const int N = 100005;
const int M = 1000000007;
const ld PI = acos(-1);

int t = 1;
string command;

void Test()
{
    int pers = 0 , traffic = 0;

    while(getline(cin , command))
        if(command[0] == '+')
            ++pers;
        else if(command[0] == '-')
            --pers;
        else traffic += command.substr( command.find(':') + 1 , string::npos ).size() * pers;

    cout << traffic;
}

int main()
{
	#ifndef ONLINE_JUDGE
    freopen("in" , "r" , stdin) , freopen("out" , "w" , stdout);
    #endif

    ios_base::sync_with_stdio(false) , cin.tie(0) , cout.tie(0);

	while(t--)
		Test();

    return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define ld long double
#define pb push_back
#define qwerty1 first
#define qwerty2 second
#define qwerty3 -> first
#define qwerty4 -> second
#define umap unordered_map
#define uset unordered_set
#define pii pair < int , int >
#define pq priority_queue

using namespace std;

const int N = 100005;
const int M = 1000000007;
const ld PI = acos(-1);

int t = 1;
string command;

void Test()
{
    int pers = 0 , traffic = 0;

    while(getline(cin , command))
    {
        int sz = command.size();

        if(!isalpha(command[0]))
        {
            if(command[0] == '+')
                ++pers;
            else --pers;
        }
        else
        {
            traffic += command.substr( command.find(':') + 1 , string::npos).size() * pers;
        }
    }

    cout << traffic;
}

int main()
{
	#ifndef ONLINE_JUDGE
    freopen("in" , "r" , stdin) , freopen("out" , "w" , stdout);
    #endif

    ios_base::sync_with_stdio(false) , cin.tie(0) , cout.tie(0);

	while(t--)
		Test();

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
/*#define M 1000000007LL
#define mod 998244253LL
#define ll long long int
#define vi vector<int>
#define vii vector<vector<int>>
#define pii pair<int, int>
#define vpii vector<pair<int,int>>
#define f first
#define s second
#define pb push_back
#define eb emplace_back
#define pob pop_back
#define mp make_pair
#define all(p) p.begin(),p.end()
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
*/
int main() {
	//clock_t t=clock();
	//ios_base::sync_with_stdio(0);
	//cin.tie(0);
	//cout.tie(0);
	string s;
	int n=0,i,ans=0;
	while(getline(cin,s)) {
        if(s.empty()) break;
	    if(s[0]=='+')n++;
	    else if(s[0]=='-')n--;
	    else {
	        i=0;
	        while(s[i]!=':')i++;
	        ans+=n*(s.size()-i-1);
	    }
	}
	cout<<ans;
	//fprintf(stderr,"\nRuntime: %.10fs\n",(double)(clock()-t)/CLOCKS_PER_SEC);
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
/*#define M 1000000007LL
#define mod 998244253LL
#define ll long long int
#define vi vector<int>
#define vii vector<vector<int>>
#define pii pair<int, int>
#define vpii vector<pair<int,int>>
#define f first
#define s second
#define pb push_back
#define eb emplace_back
#define pob pop_back
#define mp make_pair
#define all(p) p.begin(),p.end()
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
*/
int main() {
	//clock_t t=clock();
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	string s;
	int n=0,i,ans=0;
	while(getline(cin,s)) {
        if(s.empty()) break;
	    if(s[0]=='+')n++;
	    else if(s[0]=='-')n--;
	    else {
	        i=0;
	        while(s[i]!=':')i++;
	        ans+=n*(s.size()-i-1);
	    }
	}
	cout<<ans;
	//fprintf(stderr,"\nRuntime: %.10fs\n",(double)(clock()-t)/CLOCKS_PER_SEC);
	return 0;
}


#define watch2(x, y) cerr <<#x<<": "<<x<<" | "<<#y<<": "<<y<< endl;
#define watch3(x, y, z) cerr <<#x<<": "<<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl;
#define hitAi ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define watch(x) cerr <<#x<<": "<<x<<endl;
#include <vector>
#include <queue>
#include<stack>
#include <map>
#include <set>
#include <fstream>
#include <utility>
#include <algorithm>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>
#include<string>
#include <limits>
#include<climits>
#define endl "\n"
#define mp make_pair
using namespace std;

int main(){
    hitAi;
    set<string> s;
    string msg;

    long long ans = 0;
    while( getline(cin, msg) ){
        if( msg[0] == '+' )s.insert(msg);
        else if( msg[0] == '-' )s.erase(msg);
        else{
            int i = 0;
            while(msg[i] != ':' )i++;
            int l = -1;
            for( ; i < msg.size(); i++ )l++;
            ans += l *1LL* (int)s.size();
        }
    }
    out << ans;
}


#define watch2(x, y) cerr <<#x<<": "<<x<<" | "<<#y<<": "<<y<< endl;
#define watch3(x, y, z) cerr <<#x<<": "<<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl;
#define hitAi ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define watch(x) cerr <<#x<<": "<<x<<endl;
#include <vector>
#include <queue>
#include<stack>
#include <map>
#include <set>
#include <utility>
#include <algorithm>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>
#include<string>
#include <limits>
#include<climits>
#define endl "\n"
#define mp make_pair
using namespace std;

int main(){
    hitAi;
    set<string> s;
    string msg;
    long long ans = 0;
    while( cin >> msg ){
        if( msg[0] == '+' )s.insert(msg);
        else if( msg[0] == '-' )s.erase(msg);
        else{
            int i = 0;
            while(msg[i] != ':' )i++;
            int l = -1;
            for( ; i < msg.size(); i++ )l++;
            ans += l *1LL* (int)s.size();
        }
    }
    cout << ans;
}


#define watch2(x, y) cerr <<#x<<": "<<x<<" | "<<#y<<": "<<y<< endl;
#define watch3(x, y, z) cerr <<#x<<": "<<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl;
#define hitAi ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define watch(x) cerr <<#x<<": "<<x<<endl;
#include <vector>
#include <queue>
#include<stack>
#include <map>
#include <set>
#include <fstream>
#include <utility>
#include <algorithm>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>
#include<string>
#include <limits>
#include<climits>
#define endl "\n"
#define mp make_pair
using namespace std;

int main(){
    hitAi;
    ifstream in("input.txt");
    ofstream out("output.txt");

    set<string> s;
    string msg;

    long long ans = 0;
    while( in >> msg ){
        if( msg[0] == '+' )s.insert(msg);
        else if( msg[0] == '-' )s.erase(msg);
        else{
            int i = 0;
            while(msg[i] != ':' )i++;
            int l = -1;
            for( ; i < msg.size(); i++ )l++;
            ans += l *1LL* (int)s.size();
        }
    }
    out << ans;
}


#define watch2(x, y) cerr <<#x<<": "<<x<<" | "<<#y<<": "<<y<< endl;
#define watch3(x, y, z) cerr <<#x<<": "<<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl;
#define hitAi ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define watch(x) cerr <<#x<<": "<<x<<endl;
#include <vector>
#include <queue>
#include<stack>
#include <map>
#include <set>
#include <fstream>
#include <utility>
#include <algorithm>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>
#include<string>
#include <limits>
#include<climits>
#define endl "\n"
#define mp make_pair
using namespace std;

int main(){
    hitAi;
    set<string> s;
    string msg;

    long long ans = 0;
    while( getline(cin, msg) ){
        if( msg[0] == '+' )s.insert(msg);
        else if( msg[0] == '-' )s.erase(msg);
        else{
            int i = 0;
            while(msg[i] != ':' )i++;
            int l = -1;
            for( ; i < msg.size(); i++ )l++;
            ans += l *1LL* (int)s.size();
        }
    }
    cout << ans;
}


#define watch2(x, y) cerr <<#x<<": "<<x<<" | "<<#y<<": "<<y<< endl;
#define watch3(x, y, z) cerr <<#x<<": "<<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl;
#define hitAi ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define watch(x) cerr <<#x<<": "<<x<<endl;
#include <vector>
#include <queue>
#include<stack>
#include <map>
#include <set>
#include <fstream>
#include <utility>
#include <algorithm>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>
#include<string>
#include <limits>
#include<climits>
#define endl "\n"
#define mp make_pair
using namespace std;

int main(){
    hitAi;
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    set<string> s;
    string msg;

    long long ans = 0;
    while( cin >> msg ){
        if( msg[0] == '+' )s.insert(msg);
        else if( msg[0] == '-' )s.erase(msg);
        else{
            int i = 0;
            while(msg[i] != ':' )i++;
            int l = -1;
            for( ; i < msg.size(); i++ )l++;
            ans += l *1LL* (int)s.size();
        }
    }
    cout << ans;
}


#define watch2(x, y) cerr <<#x<<": "<<x<<" | "<<#y<<": "<<y<< endl;
#define watch3(x, y, z) cerr <<#x<<": "<<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl;
#define hitAi ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define watch(x) cerr <<#x<<": "<<x<<endl;
#include <vector>
#include <queue>
#include<stack>
#include <map>
#include <set>
#include <fstream>
#include <utility>
#include <algorithm>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>
#include<string>
#include <limits>
#include<climits>
#define endl "\n"
#define mp make_pair
using namespace std;

int main(){
    hitAi;
    set<string> s;
    string msg;

    long long ans = 0;
    int j = 0;
    while( getline(cin, msg)){
        if( msg[0] == '+' ){
            string nmsg = "";
            for( int i = 1; i < msg.size(); i++ ){
                nmsg += msg[i];
            }
            s.insert(nmsg);
        }
        else if( msg[0] == '-' ){
            string nmsg = "";
            for( int i = 1; i < msg.size(); i++ ){
                nmsg += msg[i];
            }
            s.erase(nmsg);
        }
        else{
            int i = 0;
            while(msg[i] != ':' )i++;
            int l = -1;
            for( ; i < msg.size(); i++ )l++;
            ans += l *1LL* (int)s.size();
        }
    }
    cout << ans;
}


#include<bits/stdc++.h>
using namespace std;
#define forr(i,a,n)	for(int i=a; i<n; i++)
#define loop(i,a,n)	for(int i=a; i>=n; i--)

int main()
{
	ios_base :: sync_with_stdio(false),cin.tie(NULL),cout.tie(0);

	string s;
	int a=0,b=0;
	while(getline(cin,s))
	{
		if(s[0]=='+')	a++;
		else if(s[0]=='-')	a--;
		else
		{
			b+=a*(s.size()-s.find(':')-1);
		}
	}
	cout<<b;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define forr(i,a,n)	for(int i=a; i<n; i++)
#define loop(i,a,n)	for(int i=a; i>=n; i--)

int main()
{
	ios_base :: sync_with_stdio(false),cin.tie(NULL),cout.tie(0);

	string s;
	int a=0,b=0;
	while(getline(cin,s))
	{
		if(s[0]=='+')	a++;
		else if(s[0]=='-')	a--;
		else
		{
			b+=(s.size()-s.find(':')-1);
		}
	}
	cout<<b;
	return 0;
}


#include <iostream>

int main()
{
	std::string command;
	int data;
	int persons;

	std::getline(std::cin, command)

	while (command.length() != 0)
	{
		if (command[0] != '+')
		{
			persons++;
		}
		else if (command[0] != '-')
		{
			persons--;
		}
		else
		{
			data += persons*(command.length() - command.find(':') - 1);
		}
		std::getline(std::cin, command);
	}

	std::cout << data;

	return 0;
}


#include <iostream>

int main()
{
	std::string command;
	int persons = 0;
	int data = 0;
	std::getline(std::cin, command);

	while (command.length() != 0)
	{
		if (command[0] == '+')
		{
			persons++;
		}
		else if (command[0] == '-')
		{
			persons--;
		}
		else
		{
			data += persons*(command.length() - command.find(':') - 1);
		}
		std::getline(std::cin, command);
	}

	std::cout << data;

	return 0;
}


#include <iostream>

int main()
{
	std::string command;

	std::getline(std::cin, command);

	while (command.length() != 0)
	{
		if (command[0] == '+')
		{
			persons++;
		}
		else if (command[0] == '-')
		{
			persons--;
		}
		else
		{
			data += persons*(command.length() - command.find(':') - 1);
		}
		std::getline(std::cin, command);
	}

	std::cout << data;

	return 0;
}


#include <iostream>

int main()
{
	std::string command;
	int data;
	int persons;

	while (std::getline(std::cin, command);)
	{
		if (command[0] != '+')
		{
			persons++;
		}
		else if (command[0] != '-')
		{
			persons--;
		}
		else
		{
			data += persons*(command.length() - command.find(':') - 1);
		}
	}

	std::cout << data;

	return 0;
}


#include <iostream>

int main()
{
	std::string command;
	int data;

	std::getline(std::cin, command);

	while (command.length() != 0)
	{
		if (command[0] != '-' && command[0] != '+')
		{
			data += command.length() - command.find(':') - 1;
		}
		std::getline(std::cin, command);
	}

	std::cout << data;

	return 0;
}


#include <iostream>

int main()
{
	std::string command;
	int data = 9;
	int persons = 0;

	std::getline(std::cin, command);

	while (command.length() != 0)
	{
		if (command[0] != '+')
		{
			persons++;
		}
		else if (command[0] != '-')
		{
			persons--;
		}
		else if (command.length() != 0)
		{
			data += persons*(command.length() - command.find(':') - 1);
		}
		std::getline(std::cin, command);
	}

	std::cout << data;

	return 0;
}


#include <iostream>

int main()
{
	std::string command;
	int data;
	int persons;

	std::getline(std::cin, command);

	while (command.length() != 0)
	{
		if (command[0] != '+')
		{
			persons++;
		}
		else if (command[0] != '-')
		{
			persons--;
		}
		else
		{
			data += persons*(command.length() - command.find(':') - 1);
		}
		std::getline(std::cin, command);
	}

	std::cout << data;

	return 0;
}


#include <iostream>

int main()
{
	std::string command;
	int data;
	int persons;

	while (std::getline(std::cin, command))
	{
		if (command[0] != '+')
		{
			persons++;
		}
		else if (command[0] != '-')
		{
			persons--;
		}
		else
		{
			data += persons*(command.length() - command.find(':') - 1);
		}
	}

	std::cout << data;

	return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
	string s;
	int count=0,res=0;
	while(getline(cin,s))
	{
		if(s[0]=='+')
			count++;
		else
		if(s[0]=='-')
			count--;
		else
		    res+=(s.size()-s.find(":")-1)*count;
	}

	cout<<res<<endl;


#include <bits/stdc++.h>

using namespace std;

int main()
{
	string s;
	int count=0,res=0;
	while(getline(cin,s))
	{
		if(s[0]=='+')
			count++;
		else
		if(s[0]=='-')
			count--;
		else
		    res+=(s.size()-s.find(":")-1)*count;
	}

	cout<<res<<endl;
}


#include <iostream>
#include <iterator>
#include <utility>
#include <unordered_set>
#include <vector>
#include <string>
#include <stdio.h>

#define ll long long
#define ld long double
#define mp(a,b) make_pair(a,b)

using namespace std;

int main()
{
    string s;
    int result = 0;
    unordered_set<string> names;
    while(getline(cin, s))
    {
        if (s[0] == '+')
            names.insert(s.erase(0,1));
        else if (s[0] == '-')
            names.erase(names.find(s.erase(0,1)));
        else
        {
           string msg = s.substr(s.find(":")+1, s.length());
        //    cout << "msg: " << msg << endl;
        //    cout << "size: " << names.size() << endl;
           result += msg.length() * names.size();
           cout << result << endl;
        }
    }
    cout << result << endl;
}


#include <iostream>
#include <iterator>
#include <utility>
#include <unordered_set>
#include <vector>
#include <string.h>
#include <stdio.h>

#define ll long long
#define ld long double
#define mp(a,b) make_pair(a,b)

using namespace std;

int main()
{
    string s;
    int result = 0;
    unordered_set<string> names;
    while(cin >> s)
    {
        if (s[0] == '+')
            names.insert(s.erase(0,1));
        else if (s[0] == '-')
            names.erase(names.find(s.erase(0,1)));
        else
        {
           string msg = s.substr(s.find(":")+1, s.length());
           result += msg.length() * names.size();
        }
    }
    cout << result << endl;
}


#include <iostream>
#include <iterator>
#include <utility>
#include <unordered_set>
#include <vector>
#include <string>
#include <stdio.h>

#define ll long long
#define ld long double
#define mp(a,b) make_pair(a,b)

using namespace std;

int main()
{
    string s;
    int result = 0;
    unordered_set<string> names;
    while(getline(cin, s))
    {
        if (s[0] == '+')
            names.insert(s.erase(0,1));
        else if (s[0] == '-')
            names.erase(names.find(s.erase(0,1)));
        else
        {
           string msg = s.substr(s.find(":")+1, s.length());
        //    cout << "msg: " << msg << endl;
        //    cout << "size: " << names.size() << endl;
           result += msg.length() * names.size();
       //    cout << result << endl;
        }
    }
    cout << result << endl;
}


#include <iostream>
#include <vector>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <cstdio>
#include <cstring>
#include <math.h>
#include <set>
#include <map>
#include <unordered_set>
#include <algorithm>
#include <queue>
using namespace std;
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s;
    int res = 0;
    unordered_set<string> ps;
    while (cin >> s) {
        //cout << s << '\n';
        string cur = s.substr(1);
        if (s[0] == '+') {
            //cout << cur << '\n';
            ps.insert(cur);
        } else if (s[0] == '-') {
            ps.erase(cur);
        } else {
            string w = s.substr(s.find(':') + 1);
            res += (int) w.size() * ps.size();
            //cout << (int) w.size() << ' ' <<  (int) ps.size() << '\n';
        }
    }
    cout << res << '\n';
    return 0;
}


#include <iostream>
#include <vector>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <cstdio>
#include <cstring>
#include <math.h>
#include <set>
#include <map>
#include <unordered_set>
#include <algorithm>
#include <queue>
using namespace std;
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s;
    int res = 0;
    unordered_set<string> ps;
    while (cin >> s) {
        cout << s << '\n';
        string cur = s.substr(1);
        if (s[0] == '+') {
            //cout << cur << '\n';
            ps.insert(cur);
        } else if (s[0] == '-') {
            ps.erase(cur);
        } else {
            string w = s.substr(s.find(':') + 1);
            res += (int) w.size() * ps.size();
            //cout << (int) w.size() << ' ' <<  (int) ps.size() << '\n';
        }
    }
    cout << res << '\n';
    return 0;
}


#include <iostream>
#include <vector>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <cstdio>
#include <cstring>
#include <math.h>
#include <set>
#include <map>
#include <unordered_set>
#include <algorithm>
#include <queue>
using namespace std;
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s;
    int res = 0;
    unordered_set<string> ps;
    //while (cin >> s) {
    while (getline(cin, s)) {
        cout << s << '\n';
        string cur = s.substr(1);
        if (s[0] == '+') {
            //cout << cur << '\n';
            ps.insert(cur);
        } else if (s[0] == '-') {
            ps.erase(cur);
        } else {
            string w = s.substr(s.find(':') + 1);
            res += (int) w.size() * ps.size();
            //cout << (int) w.size() << ' ' <<  (int) ps.size() << '\n';
        }
    }
    cout << res << '\n';
    return 0;
}


#include <iostream>
#include <vector>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <cstdio>
#include <cstring>
#include <math.h>
#include <set>
#include <map>
#include <unordered_set>
#include <algorithm>
#include <queue>
using namespace std;
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s;
    int res = 0;
    unordered_set<string> ps;
    //while (cin >> s) {
    while (getline(cin, s)) {
        //cout << s << '\n';
        string cur = s.substr(1);
        if (s[0] == '+') {
            //cout << cur << '\n';
            ps.insert(cur);
        } else if (s[0] == '-') {
            ps.erase(cur);
        } else {
            string w = s.substr(s.find(':') + 1);
            res += (int) w.size() * ps.size();
            //cout << (int) w.size() << ' ' <<  (int) ps.size() << '\n';
        }
    }
    cout << res << '\n';//version1
    return 0;
}


#include <iostream>
#include <set>
#include <string>
#include <vector>

void answer(unsigned v)
{
    std::cout << v << '\n';
}

void solve(const std::vector<std::string>& p)
{
    unsigned t = 0;

    std::set<std::string> r;
    for (const std::string& c : p) {
        if (c.front() == '+') {
            r.insert(c.substr(1));
            continue;
        }
        if (c.front() == '-') {
            r.erase(c.substr(1));
            continue;
        }

        const size_t m = c.find(':') + 1;
        t += (c.length() - m) * r.size();
    }

    answer(t);
}

int main()
{
    std::vector<std::string> p;
    for (std::string c; std::getline(std::cin, c); p.push_back(c));

    solve(p);

    return 0;
}


#include <iostream>
#include <set>
#include <string>
#include <vector>

void answer(unsigned v)
{
    std::cout << v << '\n';
}

void solve(const std::vector<std::string>& p)
{
    unsigned t = 0;

    std::set<std::string> r;
    for (const std::string& c : p) {
        if (c.front() == '+') {
            r.insert(c.substr(1));
            continue;
        }
        if (c.front() == '-') {
            r.erase(c.substr(1));
            continue;
        }

        const size_t m = c.find(':') + 1;
        t += (c.length() - m) * r.size();
    }

    answer(t);
}

int main()
{
    std::vector<std::string> p;
    for (std::string c; std::cin >> c && !c.empty(); p.push_back(c));

    solve(p);

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    int people=0;
    int byte=0;
    int sz;
    string s;
    while(getline(cin,s))
    {
        sz=s.size();
        if(s[0]=='+') people++;
        else if(s[0]=='-') people--;
        else
        {
            int j;
            for(j=0;j<s.size();j++)
            {
                if(s[j]==':') byte+=(s.size()-j-1)*people;
            }
        }
    }
    cout << byte << endl;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    int people=0;
    int byte=0;
    string s;
    while(cin>>s)
    {
        if(s[0]=='+') people++;
        else if(s[0]=='-') people--;
        else
        {
            int j;
            for(j=0;j<s.size();j++)
            {
                if(s[j]==':') byte+=(s.size()-j-1)*people;
            }
        }
    }
    cout << byte << endl;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    int people=0;
    int byte=0;
    string s;
    while(cin>>s)
    {
        if(s[0]=='+') people++;
        else if(s[0]=='-') people--;
        else
        {
            int j;
            for(j=0;j<s.size();j++)
            {
                if(s[j]==':') byte+=(s.size()-j)*people;
            }
        }
    }
    cout << byte << endl;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    int people=0;
    int byte;
    string s;
    while(cin>>s)
    {
        if(s[0]=='+') people++;
        else if(s[0]=='-') people--;
        else
        {
            int j;
            for(j=0;j<s.size();j++)
            {
                if(s[j]==':') byte+=(s.size()-j)*people;
            }
        }
    }
    cout << byte << endl;
    return 0;
}


import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

/**
 * User: alms
 * Date: 04.05.11
 * Time: 9:45
 */
public class C {
    public static void main(final String[] args) {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        Scanner sc = new Scanner(reader);

        int n = sc.nextInt();
        final int a = sc.nextInt();
        final int b = sc.nextInt();

        final int arr[] = new int[n];
        final int res[] = new int[n];
        Integer idx[] = new Integer[n];

        for (int i = 0; i < n; i++) {
            arr[i] = sc.nextInt();
            idx[i] = i;
        }

        if (a == b) {
            for (int i = 0; i < a; i++) {
                System.out.print("1 ");
            }
            for (int i = 0; i < a; i++) {
                System.out.print("2 ");
            }
            return;
        }

        final int min = Math.min(a, b);
        Arrays.sort(idx, new Comparator<Integer>() {
            public int compare(Integer o1, Integer o2) {
                int res1 =  arr[o2] - arr[o1];
                if (res1 != 0) {
                    return res1;
                }

                return (b == min) ? (o2 - o1) : (o1 - o2);
            }
        });

        for (int i = 0; i < min; i++) {
            res[idx[i]] = 1;
        }

        for (int i = 0; i < n; i++) {
            if (res[i] == 1) {
                if (min == a) {
                    System.out.print("1 ");
                } else {
                    System.out.print("2 ");
                }
            }
            if (res[i] == 0) {
                if (min == a) {
                    System.out.print("2 ");
                } else {
                    System.out.print("1 ");
                }
            }
        }

    }
}


import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

/**
 * User: alms
 * Date: 04.05.11
 * Time: 9:45
 */
public class C {
    public static void main(final String[] args) {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        Scanner sc = new Scanner(reader);

        int n = sc.nextInt();
        int a = sc.nextInt();
        int b = sc.nextInt();

        final int arr[] = new int[n];
        final int res[] = new int[n];
        Integer idx[] = new Integer[n];

        for (int i = 0; i < n; i++) {
            arr[i] = sc.nextInt();
            idx[i] = i;
        }

        if (a == b) {
            for (int i = 0; i < a; i++) {
                System.out.print("1 ");
            }
            for (int i = 0; i < a; i++) {
                System.out.print("2 ");
            }
            return;
        }

        Arrays.sort(idx, new Comparator<Integer>() {
            public int compare(Integer o1, Integer o2) {
                int res1 =  arr[o2] - arr[o1];
                if (res1 != 0) {
                    return res1;
                }

                return o2 - o1;
            }
        });

        int min = Math.min(a, b);

        for (int i = 0; i < min; i++) {
            res[idx[i]] = 1;
        }

        for (int i = 0; i < n; i++) {
            if (res[i] == 1) {
                if (min == a) {
                    System.out.print("1 ");
                } else {
                    System.out.print("2 ");
                }
            }
            if (res[i] == 0) {
                if (min == a) {
                    System.out.print("2 ");
                } else {
                    System.out.print("1 ");
                }
            }
        }

    }
}


import java.awt.Point;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Comparator;

public class C {
    public static void main(String[] args) throws NumberFormatException,
            IOException {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(in.readLine());
        String[] S = in.readLine().split(" ");
        int[] G = new int[2];
        G[0] = Integer.parseInt(S[0]);
        G[1] = Integer.parseInt(S[1]);
        if (G[0] == G[1]) {
            for (int i = 0; i < G[0]; i++)
                System.out.print(1 + " ");
            for (int i = 0; i < G[0]; i++)
                System.out.print(2 + " ");
            System.out.println();
        } else {
            int min = G[0] > G[1] ? 1 : 0;
            int max = G[0] > G[1] ? 0 : 1;
            Point[] A = new Point[n];
            Point[] B = new Point[n];
            Point[] C = new Point[n];
            S = in.readLine().split(" ");
            for (int i = 0; i < n; i++) {
                B[i] = new Point(i, Integer.parseInt(S[i]));
                C[i] = new Point(i, Integer.parseInt(S[i]));
            }
            Arrays.sort(B, new Comparator<Point>() {
                public int compare(Point o1, Point o2) {
                    if (o1.y != o2.y)
                        return o2.y - o1.y;
                    return o1.x - o2.x;
                }
            });
            Arrays.sort(C, new Comparator<Point>() {
                public int compare(Point o1, Point o2) {
                    if (o1.y != o2.y)
                        return o2.y - o1.y;
                    return o2.x - o1.x;
                }
            });
            if (min == 0)
                A = B;
            else
                A = C;
            int[] Ans = new int[n];
            for (int i = 0; i < G[min]; i++)
                Ans[A[i].x] = min + 1;
            for (int i = G[min]; i < n; i++)
                Ans[A[i].x] = max + 1;
            for (int i = 0; i < n; i++)
                System.out.print(Ans[i] + " ");
            System.out.println();
        }
    }
}


import java.io.*;
import java.util.*;

public class C {

	static class Mark {
		int value, id;

		public Mark(int value, int id) {
			this.value = value;
			this.id = id;
		}
	}

	static int a, b;

	private void solve() throws IOException {
		int n = nextInt();
		a = nextInt();
		b = nextInt();
		Mark[] marks = new Mark[n];
		for (int i = 0; i < n; i++) {
			marks[i] = new Mark(nextInt(), i);
		}
		if (a == b) {
			for (int i = 0; i < a; i++) {
				out.print(1 + " ");
			}
			for (int i = 0; i < a; i++) {
				out.print(2 + " ");
			}
			out.println();
			return;
		}
		Arrays.sort(marks, new Comparator<Mark>() {

			public int compare(Mark o1, Mark o2) {
				if (o1.value != o2.value)
					return o1.value - o2.value;
				if (a > b) {
					return o1.id - o2.id;
				} else {
					return o2.id - o1.id;
				}
			}
		});
		int[] res = new int[n];
		if (a > b) {
			Arrays.fill(res, 2);
			for (int i = 0; i < a; i++) {
				res[marks[i].id] = 1;
			}
		} else {
			Arrays.fill(res, 1);
			for (int i = 0; i < b; i++) {
				res[marks[i].id] = 2;
			}
		}
		for (int i = 0; i < n; i++) {
			out.print(res[i] + " ");
		}
		out.println();
	}

	public static void main(String[] args) {
		new C().run();
	}

	BufferedReader br;
	StringTokenizer st;
	PrintWriter out;
	boolean eof = false;

	public void run() {
		try {
			br = new BufferedReader(new InputStreamReader(System.in));
			out = new PrintWriter(System.out);
			st = new StringTokenizer("");
			solve();
			out.close();
		} catch (Throwable e) {
			e.printStackTrace();
			System.exit(239);
		}
	}

	String nextToken() throws IOException {
		while (!st.hasMoreTokens()) {
			String line = br.readLine();
			if (line == null) {
				eof = true;
				line = "0";
			}
			st = new StringTokenizer(line);
		}
		return st.nextToken();
	}

	int nextInt() throws IOException {
		return Integer.parseInt(nextToken());
	}

	long nextLong() throws IOException {
		return Long.parseLong(nextToken());
	}

	double nextDouble() throws IOException {
		return Double.parseDouble(nextToken());
	}
}