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