#include <bits/stdc++.h>
using namespace std;
map<string, int> names;
char buf[110];
int main() {
  int sum = 0;
  while (gets(buf)) {
    if (buf[0] == '+') {
      string s = string(&(buf[1]));
      names[s]++;
      continue;
    }
    if (buf[0] == '-') {
      string s = string(&(buf[1]));
      names[s] = 0;
      continue;
    }
    int i = 0;
    while (buf[i] != ':') i++;
    i = strlen(buf) - i - 1;
    map<string, int>::iterator it;
    for (it = names.begin(); it != names.end(); ++it) {
      if (it->second > 0) {
        sum += i;
      }
    }
  }
  cout << sum << endl;
  return 0;
}
