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