#include <bits/stdc++.h>
using namespace std;
int main() {
  string x;
  int count = 0;
  int total = 0;
  while (getline(cin, x)) {
    if (x[0] == '+')
      count++;
    else if (x[0] == '-')
      count--;
    else if (x[0] != '+' && x[0] != '-') {
      int l = (x.length() - 1) - x.find(':');
      total += l * count;
    }
  }
  cout << total;
  return 0;
}
