#include <bits/stdc++.h>
using namespace std;
int main(void) {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  int n = 0, k, l;
  string s;
  long long int res = 0;
  while (getline(cin, s) && s != "") {
    if (s[0] == '+')
      n++;
    else if (s[0] == '-')
      n = max(0, n - 1);
    else {
      for (long long int(i) = (long long int)(0);
           (i) < (long long int)(s.length()); (i)++)
        if (s[i] == ':') {
          k = i + 1;
          break;
        }
      l = (int)s.length() - k;
      res += l * n;
    }
  }
  cout << res << '\n';
  return 0;
}
