#include <bits/stdc++.h>
using namespace std;
struct Employee {
  int parent;
  string name;
};
int main() {
  char buf[1010];
  scanf("%s", buf);
  Employee ppl[1000];
  int stk[1000], top = 0, i = 0, n = 0;
  do {
    if (isalpha(buf[i])) {
      char s[1000] = {0};
      int j = 0;
      while (isalpha(buf[i])) s[j++] = buf[i++];
      ppl[n].name = string(s);
      ppl[n].parent = (n == 0) ? -1 : stk[top - 1];
      stk[top++] = n++;
    }
    if (buf[i] == '.') top--;
    i++;
  } while (top > 0);
  int ans = 0;
  for (int i = 1; i < n; i++) {
    string tmp = ppl[i].name;
    int j = ppl[i].parent;
    while (j >= 0) {
      if (tmp == ppl[j].name) ans++;
      j = ppl[j].parent;
    }
  }
  printf("%d\n", ans);
  return 0;
}
