#include <bits/stdc++.h>
using namespace std;
int c, d, i, n, m, k, x, y, j;
string s;
int main() {
  string s;
  while (getline(cin, s)) {
    if (s[0] == '+')
      n++;
    else if (s[0] == '-')
      n--;
    else {
      c = s.find(':');
      k += n * (s.size() - c - 1);
    }
  }
  cout << k;
}
