#include <bits/stdc++.h>
using namespace std;
int getline(char* str) {
  int i;
  char tc;
  for (i = 0; (tc = getchar()) != '\r' && tc != '\n' && !feof(stdin); i++) {
    fflush(stdout);
    str[i] = tc;
  }
  if (feof(stdin)) return 0;
  str[i] = 0;
  if (tc == '\r') getchar();
  return i;
}
int main() {
  set<string> ppl;
  char str[10000];
  int i, len, ans = 0;
  while (len = getline(str)) {
    if (str[0] == '+')
      ppl.insert((string)(str + 1));
    else if (str[0] == '-')
      ppl.erase((string)(str + 1));
    else {
      for (i = 0; i < len && ((str[i] >= 'a' && str[i] <= 'z') ||
                              (str[i] >= 'A' && str[i] <= 'z') ||
                              (str[i] >= '0' && str[i] <= '9'));
           i++)
        ;
      ans += (len - i - 1) * ppl.size();
    }
  }
  printf("%d\n", ans);
}
