#include <bits/stdc++.h>
using namespace std;
int main() {
  int l, max, min, r, k, i, flag = 0, ans = 0, temp = 0, pos = 0, neg = 0,
                            cnt = 0, d = 0, size;
  char s[109];
  for (int j = 0; j < 100; j++) {
    cin.getline(s, 105);
    if (strlen(s) == 0) {
      break;
    }
    if (s[0] == '+') temp++;
    if (s[0] == '-') temp--;
    if (s[0] != '+' && s[0] != '-') {
      i = 0;
      cnt = 0;
      while (s[i] != ':') {
        cnt++;
        i++;
      }
      k = (strlen(s) - cnt - 1);
      ans = ans + temp * k;
    }
  }
  cout << ans;
  return 0;
}
