#include <bits/stdc++.h>
int main() {
  char s1[1000], s2[1000];
  int i, j, k, l, m, n, count;
  int total;
  count = 0;
  total = 0;
  while (1) {
    if (!gets(s1)) break;
    if (s1[0] == '+')
      ++count;
    else if (s1[0] == '-')
      --count;
    else {
      l = 0;
      for (i = 0; s1[i] != ':'; i++)
        ;
      for (i = i + 1; s1[i] != '\0'; i++) ++l;
      total = total + l * count;
    }
  }
  printf("%d\n", total);
  return 0;
}
