#include <bits/stdc++.h>
using namespace std;
char s[1005], name[20], name2[20], ss[1005];
int isA(char c) {
  if (c >= 'A' && c <= 'Z') return 1;
  return 0;
}
int main() {
  while (scanf("%s", s) == 1) {
    int n = strlen(s), ret = 0;
    for (int i = 0; i < n; i++) {
      if (s[i] == ':' || s[i] == ',' || s[i] == '.') continue;
      int j = i, p = 0, q = 0;
      while (isA(s[j])) name[p++] = s[j++];
      name[p] = 0;
      i = j;
      if (s[j] == '.') continue;
      j++;
      int dep = 1, ct = 0;
      for (; dep > 0 && j < n; j++) {
        if (!isA(s[j]) && isA(s[j - 1])) {
          name2[q] = 0;
          if (strcmp(name, name2) == 0) ct++;
          q = 0;
        }
        if (isA(s[j])) {
          name2[q++] = s[j];
          if (!isA(s[j - 1])) dep++;
        } else if (s[j] == '.')
          dep--;
      }
      ret += ct;
    }
    printf("%d\n", ret);
  }
  return 0;
}
