#include <bits/stdc++.h>
using namespace std;
map<string, bool> idx;
string nama;
char msk[200];
int ans, x, y, len;
int main() {
  ans = 0;
  while (gets(msk)) switch (msk[0]) {
      case ('+'):
        len = strlen(msk);
        nama.clear();
        for (x = 1; x < len; x++) nama += msk[x];
        idx[nama] = true;
        break;
      case ('-'):
        len = strlen(msk);
        nama.clear();
        for (x = 1; x < len; x++) nama += msk[x];
        idx.erase(nama);
        break;
      default:
        nama = msk;
        x = nama.find(':');
        y = (int)nama.size() - x - 1;
        ans += y * (int)idx.size();
    }
  printf("%d\n", ans);
  return 0;
}
