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