#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  int person = 0, total = 0, l, i;
  while (getline(cin, s)) {
    if (s[0] == '+')
      person++;
    else if (s[0] == '-')
      person--;
    else {
      for (i = 0; i < s.size(); i++)
        if (s[i] == ':') break;
      l = s.size() - (i + 1);
      total += l * person;
    }
  }
  cout << total << endl;
  return 0;
}
