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