#include <bits/stdc++.h>
using namespace std;
string s;
stack<string> st;
map<string, int> cnt;
int res;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> s;
  int n = s.length();
  for (int i = 0; i < n; i++) {
    string tmp;
    while (i < n and s[i] >= 'A' and s[i] <= 'Z') {
      tmp += s[i];
      i++;
    }
    if (tmp.size() > 0) {
      res += cnt[tmp];
      st.push(tmp);
      cnt[tmp]++;
    }
    if (s[i] == '.') {
      cnt[st.top()]--;
      st.pop();
    }
  }
  cout << res << endl;
  ;
  return 0;
}
