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