#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-7;
set<string> S;
int main() {
  string s;
  int cnt = 0;
  while (getline(cin, s)) {
    if (s[0] == '-')
      S.erase(s.substr(1));
    else if (s[0] == '+')
      S.insert(s.substr(1));
    else
      cnt += (S.size() * (s.size() - s.find(':') - 1));
  }
  cout << cnt;
  return 0;
}
