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