#include <bits/stdc++.h>
int main() {
  char c, s[1000000];
  double sum = 0, l = 0;
  long i = 0;
  while (c = getchar()) {
    if (c == EOF)
      break;
    else if (c != '\n') {
      s[i++] = c;
    } else {
      if (s[0] == '+')
        ++sum;
      else if (s[0] == '-')
        --sum;
      else {
        long n = 0;
        while (s[n] != ':') ++n;
        l += (strlen(s) - n - 1) * sum;
      }
      if (s[strlen(s) - 1] == EOF) break;
      for (long f = strlen(s) - 1; f >= 0; --f) s[f] = '\0';
      i = 0;
    }
  }
  printf("%.lf", l);
}
