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