#include <bits/stdc++.h>
using namespace std;
int ans = 0;
void employee(vector<string> Test, int x = 0) {
  string name;
  char ch;
  while (cin >> ch) {
    if (isalpha(ch))
      name += ch;
    else
      break;
  }
  for (int i = 0; i < x; i++) {
    if (name == Test[i]) {
      ans++;
    }
  }
  Test.push_back(name);
  if (ch == '.') {
    return;
  } else if (ch == ':') {
    employee(Test, x + 1);
    while (cin >> ch) {
      if (ch == ',') {
        employee(Test, x + 1);
      }
      if (ch == '.') return;
    }
  }
}
int main() {
  int n = 0;
  vector<string> t;
  employee(t);
  printf("%d", ans);
  return 0;
}
