#include <bits/stdc++.h>
using namespace std;
int saldo, sum, n, i;
char line[1024];
int main() {
  saldo = sum = 0;
  while (fgets(line, 1024, stdin)) {
    line[strlen(line) - 1] = '\0';
    if (line[0] == '+')
      saldo++;
    else if (line[0] == '-')
      saldo--;
    else {
      n = strlen(line);
      for (i = 0; i < n; i++)
        if (line[i] == ':') break;
      sum += saldo * strlen(line + i + 1);
    }
  }
  printf("%d\n", sum);
  return 0;
}
