#include <bits/stdc++.h>
int main() {
  int ans = 0;
  int hum = 0;
  char mess[200];
  while (gets(mess) != NULL) {
    bool f = false;
    if (mess[0] == '+') {
      hum++;
      f = true;
    }
    if (mess[0] == '-') {
      hum--;
      f = true;
    }
    if (!f) {
      for (int i = 0, len = strlen(mess); i < len; i++) {
        if (mess[i] == ':') {
          ans += hum * strlen(mess + i + 1);
        }
      }
    }
  }
  printf("%d", ans);
}
