#include <bits/stdc++.h>
using namespace std;
int main() {
  int b = 0, sum = 0, d;
  string a;
  while (getline(cin, a)) {
    if (a[0] == '+')
      b++;
    else if (a[0] == '-')
      b--;
    else {
      for (int j = 0; j < a.size(); j++)
        if (a[j] == ':') {
          d = j + 1;
          break;
        }
      sum += (a.size() - d) * b;
    }
  }
  cout << sum;
  return 0;
}
