#include <bits/stdc++.h>
using namespace std;
template <class T1, class T2>
ostream& operator<<(ostream& os, const pair<T1, T2>& p) {
  os << "{" << p.first << " " << p.second << "}";
  return os;
}
string str(string& str, int& pos) {
  string ret = "";
  while (str[pos] <= 'Z' && str[pos] >= 'A') {
    ret += str[pos];
    pos++;
  }
  return ret;
}
int cnt = 0;
map<string, int> parse(string& s, int& pos) {
  string name = str(s, pos);
  map<string, int> low;
  if (s[pos] == ':') pos++;
  while (s[pos] != '.') {
    map<string, int> tmp = parse(s, pos);
    for (map<string, int>::iterator it = tmp.begin(); it != tmp.end(); ++it)
      low[it->first] += it->second;
    if (s[pos] == ',') pos++;
  }
  pos++;
  cnt += low[name];
  low[name]++;
  return low;
}
int main() {
  string s;
  cin >> s;
  int t = 0;
  parse(s, t);
  cout << cnt << endl;
  return 0;
}
