#include <bits/stdc++.h>
using namespace std;
long long ma = -1e9, mi = 1e9;
using namespace std;
int const N = 1e5;
int main() {
  string s, a;
  set<string> my;
  int x = 0, ans = 0;
  while (getline(cin, s)) {
    if (s[0] == '-') {
      s.erase(0, 1);
      my.erase(s);
    } else if (s[0] == '+') {
      s.erase(0, 1);
      my.insert(s);
    } else {
      string a = "";
      char c = s[0];
      for (int i = 1; i < s.size(); ++i) {
        if (s[i] == ':') break;
        a += s[i];
      }
      int x = s.size() - (a.size() + 2);
      ans += (x * my.size());
    }
  }
  cout << ans;
}
