#include <bits/stdc++.h>
using namespace std;
vector<string> names;
vector<int> par;
stringstream ss;
void parse(int parent) {
  string str;
  char c;
  while (isalpha(ss.peek())) ss >> c, str += c;
  names.push_back(str);
  par.push_back(parent);
  int cur = par.size() - 1;
  while (ss.peek() == ',' || ss.peek() == ':') {
    ss >> c;
    parse(cur);
  }
  ss >> c;
}
int main() {
  string str;
  cin >> str;
  ss << str;
  parse(-1);
  int ans = 0;
  for (int i = 0; i < par.size(); i++) {
    int j = par[i];
    while (j != -1) {
      if (names[i] == names[j]) ans++;
      j = par[j];
    }
  }
  cout << ans << endl;
  return 0;
}
