#include <bits/stdc++.h>
using namespace std;
string name[1000];
string s;
int see = 0;
int lv = 0;
int answer = 0;
string read() {
  string rep(1000, 'a');
  for (int i = 0; 1; i++) {
    if (s[see + i] != ':' && s[see + i] != '.')
      rep[i] = s[see + i];
    else {
      see += i;
      rep[i] = '\0';
      break;
    }
  }
  name[lv] = rep;
  lv++;
  for (int i = 0; i < lv - 1; i++) {
    if (rep == name[i]) answer++;
  }
  return rep;
}
int main() {
  cin >> s;
  string temp;
  while (see < s.size()) {
    if (s[see] == ':')
      see++;
    else if (s[see] == '.') {
      see++;
      lv--;
    } else if (s[see] == ',') {
      see++;
    } else
      temp = read();
  }
  cout << answer;
  return 0;
}
