#include <bits/stdc++.h>
using namespace std;
string structure;
int N;
stack<int> st;
int p[1010];
string name[1010];
int main(void) {
  int i, j;
  cin >> structure;
  string s;
  for ((i) = 0; (i) < (int)(structure.length()); (i)++) {
    char ch = structure[i];
    if (ch >= 'A' && ch <= 'Z') {
      s += ch;
    } else if (ch == '.' || ch == ':') {
      if (!s.empty()) {
        name[N] = s;
        if (!st.empty())
          p[N] = st.top();
        else
          p[N] = -1;
        st.push(N);
        N++;
        s = "";
      }
      if (ch == '.') st.pop();
    }
  }
  int ans = 0;
  for ((i) = 0; (i) < (int)(N); (i)++)
    for (j = p[i]; j >= 0; j = p[j])
      if (name[i] == name[j]) ans++;
  cout << ans << endl;
  return 0;
}
