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