#include <bits/stdc++.h>
using namespace std;
int solve(string &s, int start, int &end, vector<string> &parents) {
  int ans = 0;
  string name = "";
  int i = start;
  int len = s.length();
  while (s[i] >= 'A' && s[i] <= 'Z') name += s[i++];
  ans = count(parents.begin(), parents.end(), name);
  if (s[i] == '.') {
    end = i;
    return ans;
  }
  parents.push_back(name);
  while (s[i] == ':' || s[i] == ',') {
    ans += solve(s, i + 1, end, parents);
    i = end + 1;
  }
  end = i;
  parents.pop_back();
  return ans;
}
int main() {
  string s = "";
  int end = 0;
  vector<string> parents;
  cin >> s;
  cout << solve(s, 0, end, parents);
  return 0;
}
