#include <bits/stdc++.h>
using namespace std;
int main() {
  int renshu = 0;
  int zijieshu = 0;
  string oper;
  while (getline(cin, oper, '\n')) {
    if (oper[0] == '+') {
      renshu++;
    } else if (oper[0] == '-') {
      renshu--;
    } else {
      int kal = oper.find(':', 0);
      zijieshu += (oper.size() - kal - 1) * renshu;
    }
  }
  cout << zijieshu << endl;
  return 0;
}
