#include <bits/stdc++.h>
using namespace std;
int main() {
  char input[1000000];
  int participants = 0;
  int traffic = 0;
  int i, j;
  while (gets(input) != NULL) {
    if (input[0] == '+')
      ++participants;
    else if (input[0] == '-')
      --participants;
    else {
      char message[100000];
      int len = strlen(input);
      for (i = 0; i < len && input[i] != ':'; ++i)
        ;
      ++i;
      for (j = 0; i <= len; ++i, ++j) message[j] = input[i];
      traffic += strlen(message) * (participants);
    }
  }
  printf("%d\n", traffic);
  return 0;
}
