#include <bits/stdc++.h>
using namespace std;
inline void wait() {
  getchar();
  getchar();
}
int main(void) {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  long long cnt = 0;
  string s;
  cin >> s;
  int i = 0;
  vector<string> res;
  while (i < s.size()) {
    if (s[i] == ':' || s[i] == ',') {
      i++;
      continue;
    }
    if (s[i] == '.') {
      res.pop_back();
      i++;
      continue;
    }
    string name;
    while (i < s.size() && s[i] >= 'A' && s[i] <= 'Z') {
      name += s[i];
      i++;
    }
    for (int k = 0; k < res.size(); k++)
      if (res[k] == name) cnt++;
    res.push_back(name);
  }
  cout << cnt;
  wait();
}
