#include <bits/stdc++.h>
char s[1001];
char a[1001][20];
int ans;
int main() {
  int i, j, k = 0, l = 0;
  char c[20];
  memset(c, 0, sizeof(c));
  scanf("%s", s);
  for (i = 0; s[i] != 0; i++)
    if (s[i] >= 'A' && s[i] <= 'Z') {
      c[l] = s[i];
      l++;
    } else {
      if (l != 0)
        for (j = 1; j <= k; j++)
          if (strcmp(a[j], c) == 0) ans++;
      if (l != 0) {
        k++;
        strcpy(a[k], c);
      }
      if (s[i] == '.') --k;
      memset(c, 0, sizeof(c));
      l = 0;
    }
  printf("%d\n", ans);
  return 0;
}
