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