#include <bits/stdc++.h>
using namespace std;
long long ans;
void addem(string s, int &p, map<string, int> mp) {
  int i = p;
  while (s[i] >= 'A' && s[i] <= 'Z') i++;
  string t = s.substr(p, i - p);
  ans += mp[t];
  p = i;
  if (s[p] == '.') {
    p++;
    return;
  }
  mp[t]++;
  while (s[p] != '.') {
    p++;
    addem(s, p, mp);
  }
  p++;
}
int main() {
  string s;
  cin >> s;
  int p = 0;
  map<string, int> mp;
  addem(s, p, mp);
  cout << ans;
  return 0;
}
