#include <bits/stdc++.h>
using namespace std;
int c = 0;
int h(string s, vector<string> p) {
  string name;
  while (s[c] != ':' && s[c] != '.') {
    name += s[c];
    c++;
  }
  int res = count(p.begin(), p.end(), name);
  if (s[c] == '.') {
    c++;
    return res;
  }
  p.push_back(name);
  c++;
  while (true) {
    res += h(s, p);
    if (s[c] == '.') break;
    c++;
  }
  c++;
  return res;
}
int main() {
  string s;
  cin >> s;
  vector<string> p;
  cout << h(s, p) << endl;
  return 0;
}
