#include <bits/stdc++.h>
using namespace std;
int it = 0;
vector<string> employees;
vector<int> sub[500];
int readName(string code) {
  string str;
  int i = 0;
  while ('A' <= code[it] && code[it] <= 'Z') {
    str += code[it];
    it++;
    i++;
  }
  employees.push_back(str);
  return employees.size() - 1;
}
int readEmployee(string code) {
  int r = readName(code);
  if (code[it] == ':') {
    do {
      it++;
      sub[r].push_back(readEmployee(code));
    } while (code[it] == ',');
  }
  if (code[it] == '.') {
    it++;
  }
  return r;
}
int findName(string name, int num) {
  int r = 0;
  for (int i = 0; i < sub[num].size(); i++) {
    if (name.compare(employees[sub[num][i]]) == 0) r++;
    r += findName(name, sub[num][i]);
  }
  return r;
}
int main() {
  string code;
  cin >> code;
  readEmployee(code);
  int r = 0;
  for (int i = 0; i < employees.size(); i++) {
    r += findName(employees[i], i);
  }
  cout << r << endl;
}
