#include <bits/stdc++.h>
using namespace std;
char s[1005];
int main() {
  int ret = 0;
  int p = 0;
  while (gets(s)) {
    if (s[0] == '+')
      p++;
    else if (s[0] == '-')
      p--;
    else {
      int cnt = 0;
      while (s[cnt] != ':') cnt++;
      ret += (strlen(s) - cnt - 1) * p;
    }
  }
  printf("%d\n", ret);
  return 0;
}
