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