#include <bits/stdc++.h>
using namespace std;
map<string, int> cnt;
int gor() {
  char n[1005];
  scanf("%[A-Z]", n);
  int col = cnt[n];
  cnt[n]++;
  while (getchar() != '.') col += gor();
  cnt[n]--;
  return col;
}
int main() { printf("%d\n", gor()); }
