#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
const int inf = 2e9;
const int mod = 1e9 + 7;
const long long INF = 2e18;
string s, t;
set<string> q;
int res;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  while (getline(cin, s)) {
    t = "";
    if (s[0] == '+') {
      q.insert(s.substr(1));
    } else if (s[0] == '-') {
      q.erase(s.substr(1));
    } else {
      int i = 0;
      while (s[i] != ':') {
        ++i;
      }
      ++i;
      for (; i < (int)s.size(); ++i) {
        res += (int)q.size();
      }
    }
  }
  cout << res;
  return 0;
}
