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