#include <bits/stdc++.h>
using namespace std;
int dirx[] = {0, 0, 1, -1, 0};
int diry[] = {1, -1, 0, 0, 0};
void solve() {
  string s;
  int cnt = 0, sum = 0;
  while (getline(cin, s)) {
    if (s[0] == '+')
      cnt++;
    else if (s[0] == '-')
      cnt--;
    else {
      int l = s.length();
      int idx;
      for (int i = 0; i < l; i++) {
        if (s[i] == ':') {
          idx = i + 1;
          break;
        }
      }
      sum += (l - idx) * cnt;
    }
  }
  cout << sum << endl;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  solve();
}
