#include <bits/stdc++.h>
int main(void) {
  using namespace std;
  ios_base::sync_with_stdio(false);
  unordered_set<string> names;
  int traffic = 0;
  while (1) {
    string line;
    getline(cin, line);
    if (!cin) {
      cout << traffic;
      return 0;
    }
    if (line[0] == '+') {
      names.insert(line.substr(1, string::npos));
    } else if (line[0] == '-') {
      names.erase(line.substr(1, string::npos));
    } else {
      int k = line.find(":");
      traffic += (line.size() - k - 1) * names.size();
    }
  }
}
