#include <bits/stdc++.h>
using namespace std;
int main() {
  int sum = 0, cnt = 0, l, i;
  string ch;
  while (1) {
    getline(cin, ch);
    if (ch.size() == 0) break;
    if (ch[0] == '+')
      cnt++;
    else if (ch[0] == '-')
      cnt--;
    else {
      l = ch.size();
      for (i = 0; i < l; i++) {
        if (ch[i] == ':') {
          break;
        }
      }
      sum = sum + ((l - i - 1) * cnt);
    }
  }
  printf("%d\n", sum);
  return 0;
}
