#include <bits/stdc++.h>
using namespace std;
map<string, int> m;
string line;
int ans;
int go(int pos) {
  string name = "";
  int end;
  for (int i = pos; i < line.length(); i++) {
    if (line[i] >= 'A' && line[i] <= 'Z') {
      name += line[i];
    } else {
      end = i;
      break;
    }
  }
  map<string, int>::iterator p = m.find(name);
  if (p != m.end()) {
    ans += p->second;
    p->second = p->second + 1;
  } else {
    m[name] = 1;
  }
  while (line[end] != '.') {
    end = go(end + 1);
  }
  p = m.find(name);
  p->second = p->second - 1;
  return end + 1;
}
int main() {
  cin >> line;
  ans = 0;
  go(0);
  cout << ans << endl;
  return 0;
}
