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