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