#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  int p = 0, ans = 0;
  while (getline(cin, s)) {
    if (s[0] == '+')
      p++;
    else if (s[0] == '-')
      p--;
    else
      ans += p * (s.length() - s.find(':') - 1);
  }
  cout << ans << endl;
}
