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