#include <bits/stdc++.h>
using namespace std;
int main() {
  int peo = 0, ans = 0;
  string s;
  while (getline(cin, s)) {
    if (s[0] == '+') {
      peo++;
    } else if (s[0] == '-') {
      peo--;
    } else {
      int add = s.length();
      for (int i = 0; i < s.length(); i++) {
        add--;
        if (s[i] == ':') {
          break;
        }
      }
      ans += peo * add;
    }
  }
  cout << ans + 1 - 1;
  return 0;
}
