#include <bits/stdc++.h>
using namespace std;
char c;
int s = 0, t = 0;
int main() {
  while (scanf("%c", &c) != -1) {
    if (c == '+')
      t++;
    else if (c == '-')
      t--;
    else {
      while (c != ':') scanf("%c", &c);
      while (c != '\n') {
        s += t;
        scanf("%c", &c);
      }
      s -= t;
    }
    while (c != '\n') scanf("%c", &c);
  }
  printf("%d\n", s);
  return 0;
}
