#include <bits/stdc++.h>
using namespace std;
void solve();
signed main() { solve(); }
string getstring(string &s) {
  cin >> s;
  return s;
}
void solve() {
  string s;
  long long p = 0, l = 0, x, i;
  char ch;
  while (scanf("%c", &ch) != EOF) {
    getline(cin, s);
    if (ch == '+')
      p++;
    else if (ch == '-')
      p--;
    else {
      for (i = 0; i <= s.length(); i++) {
        if (s[i] == ':') {
          break;
        }
      }
      l += ((s.length() - i - 1) * p);
    }
  }
  cout << l;
}
