#include <bits/stdc++.h>
using namespace std;
char str[1005];
int main() {
  int cnt = 0;
  int ans = 0;
  while (gets(str)) {
    if (str[0] == '+')
      cnt++;
    else if (str[0] == '-')
      cnt--;
    else {
      for (int i = 0; i < strlen(str); ++i)
        if (str[i] == ':') ans += (strlen(str) - i - 1) * cnt;
    }
  }
  printf("%d\n", ans);
}
