#include <bits/stdc++.h>
using namespace std;
long i = 0, j;
string s;
string name() {
  string ss = "";
  while (s[i] >= 'A' && s[i] <= 'Z') ss += s[i++];
  return ss;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  long ans = 0;
  cin >> s;
  std::vector<string> v;
  string ss = name();
  v.push_back(ss);
  while (i < s.length()) {
    if (s[i] == '.')
      v.pop_back(), i++;
    else {
      i++;
      string str = name();
      for (int j = 0; j < v.size(); j++) {
        if (v[j] == str) ans++;
      }
      v.push_back(str);
    }
  }
  cout << ans;
  return 0;
}
