#include <bits/stdc++.h>
using namespace std;
using namespace std;
int main() {
  vector<pair<string, int> > v;
  string s, name = "";
  int k = -1, ans = 0;
  cin >> s;
  for (int i = 0; i < s.length(); i++)
    if (s[i] == ':') {
      v.push_back(make_pair(name, k));
      k = v.size() - 1;
      name = "";
    } else if (s[i] == '.') {
      if (name.length() > 0) {
        v.push_back(make_pair(name, k));
        name = "";
      } else
        k = v[k].second;
    } else if (s[i] != ',') {
      name += s[i];
    }
  int n = v.size();
  for (int i = n - 1; i >= 0; i--) {
    int j = v[i].second;
    while (j != -1) {
      if (v[i].first == v[j].first) {
        ans++;
      }
      j = v[j].second;
    }
  }
  cout << ans;
  return 0;
}
