#include <bits/stdc++.h>
using namespace std;
int main() {
  string com;
  map<string, bool> mp;
  int ans = 0;
  while (getline(cin, com)) {
    if (com[0] == '+') {
      com.erase(com.begin(), com.begin() + 1);
      mp[com] = 1;
    } else if (com[0] == '-') {
      com.erase(com.begin(), com.begin() + 1);
      mp[com] = 0;
    } else {
      int len = com.size() - com.find(':') - 1, cnt = 0;
      for (map<string, bool>::iterator it = mp.begin(); it != mp.end(); it++) {
        if (it->second) cnt++;
      }
      ans += cnt * len;
    }
  }
  cout << ans << endl;
  return 0;
}
