#include <bits/stdc++.h>
using namespace std;
int main() {
  string str;
  int cnt = 0, res = 0;
  while (getline(cin, str)) {
    if (str[0] == '+')
      cnt++;
    else if (str[0] == '-')
      cnt--;
    else {
      int index = str.find(":");
      int len = str.length() - 1 - index;
      res += (cnt * len);
    }
  }
  cout << res << endl;
  return 0;
}
