#include <bits/stdc++.h>
using namespace std;
int main() {
  int i, sum, a, j;
  char z[105];
  i = 0;
  sum = 0;
  while (gets(z)) {
    if (z[0] == '+') {
      i++;
    } else if (z[0] == '-') {
      i--;
    } else {
      for (a = 0; strlen(z) > a; a++) {
        if (z[a] == ':') {
          break;
        }
      }
      j = strlen(z) - a - 1;
      sum += i * j;
    }
  }
  cout << sum << endl;
  return 0;
}
