#include <bits/stdc++.h>
using namespace std;
char buf[1000];
int main() {
  int res = 0;
  int ic = 0;
  while (gets(buf)) {
    if (buf[0] == '+')
      ic++;
    else if (buf[0] == '-')
      ic--;
    else {
      int x = 0;
      while (buf[x] != ':') x++;
      int len = 0;
      x++;
      while (buf[x]) {
        x++;
        len++;
      }
      res += len * ic;
    }
  }
  printf("%d\n", res);
  return 0;
}
