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

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

#include <bits/stdc++.h>
#include <stdio.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <iostream>
#include <cmath>
#include <math.h>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <map>

using namespace std;
using namespace __gnu_pbds;

#define     ll          long long
#define     ld          long double
#define     X           real()
#define     Y           imag()
#define     get         cin >>
#define     out         cout <<
#define     and_        >>
#define     with        <<
#define     space       with " " with
#define     space_e     with " "
#define     all         with "\n"
#define     all_e       "\n"
#define     getl(x)     getline(cin, x)
#define     var         auto

typedef tree<ll, null_type, less <ll>, rb_tree_tag, tree_order_statistics_node_update> indexed_set_i;
typedef tree<ld, null_type, less <ld>, rb_tree_tag, tree_order_statistics_node_update> indexed_set_f;
typedef tree<string, null_type, less <string>, rb_tree_tag, tree_order_statistics_node_update> indexed_set_s;
typedef complex <ll> coordination_2D_i;
typedef complex <ld> coordination_2D_f;

template <typename TYPE_1>
void Print (vector <TYPE_1> TEMP_A) {
    if (TEMP_A.size() == 0) return;
    ll TEMP_X;
    for (TEMP_X = 0; TEMP_X < TEMP_A.size() - 1; TEMP_X++)
        out TEMP_A[TEMP_X] space_e;
    out TEMP_A[TEMP_A.size() - 1] all;
}
template <typename TYPE_1>
void Print (deque <TYPE_1> TEMP_A) {
    if (TEMP_A.size() == 0) return;
    ll TEMP_X;
    for (TEMP_X = 0; TEMP_X < TEMP_A.size() - 1; TEMP_X++)
        out TEMP_A[TEMP_X] space_e;
    out TEMP_A[TEMP_A.size() - 1] all;
}
template <typename TYPE_1>
void Print (vector < vector <TYPE_1> > TEMP_A) {
    ll TEMP_X, TEMP_Y;
    for (TEMP_X = 0; TEMP_X < TEMP_A.size(); TEMP_X++) {
        for (TEMP_Y = 0; TEMP_Y < TEMP_A[TEMP_X].size() - 1; TEMP_Y++)
            out TEMP_A[TEMP_X][TEMP_Y] space_e;
        if (TEMP_A[TEMP_X].size() > 0)
            out TEMP_A[TEMP_X][TEMP_A[TEMP_X].size() - 1];
        cout all;
    }
}
template <typename TYPE_1>
void Print (deque < deque <TYPE_1> > TEMP_A) {
    ll TEMP_X, TEMP_Y;
    for (TEMP_X = 0; TEMP_X < TEMP_A.size(); TEMP_X++) {
        for (TEMP_Y = 0; TEMP_Y < TEMP_A[TEMP_X].size() - 1; TEMP_Y++)
            out TEMP_A[TEMP_X][TEMP_Y] space_e;
        if (TEMP_A[TEMP_X].size() > 0)
            out TEMP_A[TEMP_X][TEMP_A[TEMP_X].size() - 1];
        cout all;
    }
}

/// OTHER - Begin



/// OTHER - End

void MainFunction2 () {

    //ios::sync_with_stdio(0);
    //cin.tie(0);

    /// Code - Begin

    set <string> u;
    ll s = 0, y;
    string a, b;

    while (getl(a)) {
        if (a[0] == '+') {
            b = a;
            b.erase(0, 1);
            u.insert(b);
        }else if (a[0] == '-') {
            b = a;
            b.erase(0, 1);
            u.erase(b);
        }else {
            for (y = 0; y < a.length(); y++)
                if (a[y] == ':') {
                    s += (a.length() - (y + 1)) * u.size();
                    break; }
        }
        out s all;
    }

    out s all;

    /// Code - End
}

int main () {

    //ios::sync_with_stdio(0);
    //cin.tie(0);

    ll T_NUM = 1;
    //get T_NUM;

    while (T_NUM--)
        MainFunction2();

    return 0;
}