#include <bits/stdc++.h>
struct state {
  int length, sum;
};
struct employee {
  const char *name;
  const employee *super;
};
static int name_length(const char *s) {
  int n = 0;
  while ('A' <= s[n] && s[n] <= 'Z') n++;
  return n;
}
static state operator+(const state &a, const state &b) {
  return {a.length + b.length, a.sum + b.sum};
}
static state pairs(const char *s, const employee *super) {
  const employee e = {s, super};
  state t = {name_length(s), 0};
  for (const employee *i = super; i != nullptr; i = i->super)
    t.sum += t.length == name_length(i->name) &&
             strncmp(e.name, i->name, t.length) == 0;
  if (s[t.length++] == ':') do
      t = t + pairs(&s[t.length], &e);
    while (s[t.length++] == ',');
  return t;
}
int main(int argc, char *argv[]) {
  char s[1002];
  if (scanf("%1001s", s) != 1 || strlen(s) < 1 || strlen(s) == 1001) {
    fprintf(stderr, "scanf: Header IO error.\n");
    exit(EXIT_FAILURE);
  }
  printf("%d\n", pairs(s, nullptr).sum);
  return EXIT_SUCCESS;
}
