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