#include <bits/stdc++.h>
using namespace std;
int uz, in, x, sayac;
int main() {
  string a;
  while (getline(cin, a)) {
    if (a[0] == '+')
      in++;
    else if (a[0] == '-')
      in--;
    else {
      sayac += (a.size() - a.find(':') - 1) * in;
    }
  }
  printf("%d", sayac);
  return 0;
}
