#include <bits/stdc++.h>
using namespace std;
int main() {
  int n = 0, l = 0;
  while (cin.peek() != EOF) {
    string s;
    s = "";
    getline(cin, s);
    if (s[0] == '+') {
      n++;
      continue;
    }
    if (s[0] == '-') {
      n--;
      continue;
    } else {
      int j = 0;
      for (int i = 0; i < s.size(); i++) {
        if (s[i] == ':') {
          j = i + 1;
          break;
        }
      }
      l += (s.size() - j) * n;
    }
  }
  cout << l;
}
