#include <bits/stdc++.h>
using namespace std;
int main() {
  char cmd[101];
  char msg[99] = {};
  int res = 0;
  int online = 0;
  while (gets(cmd)) {
    if (cmd[0] == '+')
      ++online;
    else if (cmd[0] == '-')
      --online;
    else {
      char *p = cmd;
      size_t size = 0;
      while (*p != ':') p++;
      while (*(++p)) size++;
      res += size * online;
    }
  }
  cout << res << endl;
  return 0;
}
