#include <bits/stdc++.h>
using namespace std;
const int MAXL = 109;
char str[MAXL];
int j, len;
int cnt, ans;
int main() {
  cnt = ans = 0;
  while (gets(str)) {
    if (str[0] == '+')
      cnt++;
    else if (str[0] == '-')
      cnt--;
    else {
      for (j = 0; str[j] != ':'; j++)
        ;
      for (len = 0, j++; str[j] != '\0'; j++) len++;
      ans += len * cnt;
    }
  }
  cout << ans << endl;
  return 0;
}
