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