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