#include <bits/stdc++.h>
using namespace std;
int main() {
  int i, n, len, j, flag = 0, dot, free, k, ans = 0, x;
  char ins[100001];
  int no[1000];
  scanf("%s", ins);
  len = strlen(ins);
  char name[len][101];
  j = 0;
  n = 0;
  for (i = 0; i <= len - 1; i++) {
    if (ins[i] > 64 && ins[i] < 91) {
      if (flag == 0) no[n] = i;
      flag = 1;
      name[n][j++] = ins[i];
    } else if (flag != 0) {
      flag = 0;
      n++;
      j = 0;
    }
  }
  dot = 0;
  free = 0;
  for (i = n - 1; i >= 0; i--) {
    dot = 0;
    flag = 0;
    x = i;
    for (j = no[i] - 1; j >= 0; j = k) {
      if (ins[j] == '.') {
        dot++;
        k = j - 1;
      } else if (ins[j] > 64 && ins[j] < 91) {
        x--;
        if (dot <= 0 && strcmp(name[i], name[x]) == 0) {
          ans++;
          dot = 0;
          k = no[x] - 1;
          continue;
        }
        if (dot > 0) dot--;
        k = no[x] - 1;
      } else
        k = j - 1;
    }
  }
  printf("%d", ans);
}
