#include <bits/stdc++.h>
using namespace std;
vector<string> pars;
string s;
int main() {
  int cnt = 0;
  cin >> s;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == '.') pars.pop_back();
    if (s[i] == ',' || s[i] == ':' || s[i] == '.') continue;
    string newS = "";
    while (s[i] >= 'A' && s[i] <= 'Z') newS += s[i], i++;
    for (int j = 0; j < pars.size(); j++)
      if (pars[j] == newS) cnt++;
    pars.push_back(newS);
    i--;
  }
  cout << cnt << endl;
  return 0;
}
