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