#include <bits/stdc++.h>
using namespace std;
string cad;
int i = 0;
int ret = 0;
map<string, int> _map;
void _solve() {
  string a = "";
  while (isalpha(cad[i])) a += cad[i++];
  ret += _map[a];
  _map[a]++;
  while (cad[i] != '.') {
    i++;
    _solve();
  }
  i++;
  _map[a]--;
}
int main() {
  cin >> cad;
  _solve();
  printf("%d\n", ret);
  return 0;
}
