#include <bits/stdc++.h>
using namespace std;
char a[1005];
string st;
int main() {
  scanf("%s", a);
  int len = strlen(a), ans = 0;
  for (int i = 0; i < len; i++) {
    int j = i;
    if (a[j] < 'A' || a[j] > 'Z') continue;
    st = "";
    while (a[j] >= 'A' && a[j] <= 'Z') {
      st = st + a[j];
      j++;
    }
    int next = j - 1;
    if (a[j] == '.') {
      i = j;
      continue;
    }
    int now = 1;
    j++;
    while (true) {
      if (now == 0) break;
      if (a[j] == '.')
        now--;
      else if (a[j] >= 'A' && a[j] <= 'Z') {
        now++;
        int k = j;
        string st1 = "";
        while (a[k] >= 'A' && a[k] <= 'Z') {
          st1 = st1 + a[k];
          k++;
        }
        k--;
        if (st1 == st) ans++;
        j = k;
      }
      j++;
    }
    i = next;
  }
  printf("%d\n", ans);
}
