#include <bits/stdc++.h>
char s[1001];
struct nam {
  int num;
  char name[10];
} names[1000];
int stack[1000];
int names_len = 0;
int stack_len = 0;
int main() {
  gets(s);
  char name_t[12];
  nam t;
  int i;
  int shift = 0;
  char c;
  int was;
  int counter = 0;
  sscanf(s + shift, "%[A-Z]s", t.name);
  t.num = 0;
  names[names_len] = t;
  stack[0] = 0;
  stack_len++;
  names_len++;
  shift += strlen(t.name);
  while (stack_len > 0) {
    if (s[shift] == ':') {
      shift++;
    } else {
      while (s[shift] != ',' && stack_len > 0) {
        stack_len--;
        shift++;
      }
      shift++;
    }
    if (stack_len == 0) continue;
    sscanf(s + shift, "%[A-Z]s", t.name);
    was = 0;
    for (i = 0; i < names_len; i++)
      if (strcmp(t.name, names[i].name) == 0) {
        t.num = names[i].num;
        was = 1;
        break;
      }
    if (!was) {
      t.num = names_len;
      names[names_len] = t;
      names_len++;
    } else {
      for (i = 0; i < stack_len; i++)
        if (stack[i] == t.num) counter++;
    }
    stack[stack_len] = t.num;
    stack_len++;
    shift += strlen(t.name);
  }
  printf("%d", counter);
  return 0;
}
