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