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