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