#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  unordered_set<string> set;
  unsigned int bytes = 0;
  while (getline(cin, s)) {
    if (s[0] == '+')
      set.insert(s.substr(1, s.size()));
    else if (s[0] == '-')
      set.erase(s.substr(1, s.size()));
    else {
      unsigned int pos = s.find(':');
      string message = s.substr(pos + 1, s.size());
      bytes += (message.size() * set.size());
    }
  }
  cout << bytes;
}
