#include <bits/stdc++.h>
char st[1100];
char name[2000][20];
int p[2000];
int cnt;
int input(int par, int a) {
  int idx = a;
  while (st[idx] >= 'A' && st[idx] <= 'Z') {
    idx++;
  }
  int cur = cnt++;
  p[cur] = par;
  for (int i = a; i < idx; i++) {
    name[cur][i - a] = st[i];
  }
  name[cur][idx - a] = 0;
  if (st[idx] == '.') return idx + 1;
  if (st[idx] == ':') {
    int tmp = idx + 1;
    while (1) {
      int fuck = input(cur, tmp);
      if (st[fuck] == ',') {
        tmp = fuck + 1;
      } else
        return fuck + 1;
    }
  }
}
int solve(int a) {
  int mb = p[a], res = 0;
  while (mb >= 0) {
    if (!strcmp(name[mb], name[a])) res++;
    mb = p[mb];
  }
  return res;
}
int main() {
  gets(st);
  input(-1, 0);
  int ans = 0;
  for (int i = 0; i < cnt; i++) {
    ans += solve(i);
  }
  printf("%d\n", ans);
  return 0;
}
