#include <bits/stdc++.h>
using namespace std;
int main() {
  char com[200];
  char *p;
  int man = 0;
  int sum = 0;
  int i;
  int word;
  while (scanf("%c", com) == 1) {
    i = 1;
    while ((com[i] = getchar()) != '\n') i++;
    com[i] = '\0';
    word = 0;
    if (com[0] == '+') {
      man++;
      continue;
    }
    if (com[0] == '-') {
      man--;
      continue;
    }
    p = strchr(com, ':');
    p += 1;
    while (*(p++) != '\0') {
      word++;
    }
    sum += word * man;
  }
  printf("%d", sum);
}
