#include <bits/stdc++.h>
using namespace std;
map<string, int> cnt;
int dfs() {
  char name[20];
  scanf("%[A-Z]", name);
  int cal = cnt[name]++;
  while (getchar() != '.') cal += dfs();
  cnt[name]--;
  return cal;
}
int main() {
  cout << dfs() << endl;
  return 0;
}
