#include <bits/stdc++.h>
using namespace std;
int Res, k;
string s, a[50000], name;
int main() {
  cin >> s;
  for (int i = 0; i < s.size(); ++i) {
    if (isupper(s[i])) name += s[i];
    if (s[i] == ':') {
      a[k++] = name;
      for (int j = 0; j < k - 1; ++j)
        if (name == a[j]) ++Res;
      name = "";
    }
    if (s[i] == '.') {
      if (name == "") k--;
      for (int j = 0; j < k; ++j)
        if (name == a[j]) ++Res;
      name = "";
    }
  }
  printf("%d", Res);
  return 0;
}
