#include <bits/stdc++.h>
using namespace std;
int msg(string str) {
  size_t found;
  string str2;
  found = str.find(":");
  str2 = str.substr(int(found) + 1);
  return str2.length();
}
int main() {
  int total = 0, people = 0;
  string str;
  while (getline(cin, str)) {
    if (str[0] == '+') {
      people++;
      continue;
    } else if (str[0] == '-') {
      people--;
      continue;
    } else {
      total += people * msg(str);
    }
  }
  cout << total;
  return 0;
}
