#include <bits/stdc++.h>
using namespace std;
signed main() {
  string s;
  cin >> s;
  vector<string> arr;
  string he;
  long long ans = 0;
  stack<string> st;
  long long sum = 0;
  map<string, long long> mp;
  for (long long i = 0; i < s.length(); i++) {
    if (isalpha(s[i])) {
      he.push_back(s[i]);
    } else {
      if (he.size() > 0) {
        sum += mp[he];
        st.push(he);
        mp[he]++;
        he.clear();
      }
      if (s[i] == '.') {
        string a = st.top();
        mp[a]--;
        st.pop();
      }
    }
  }
  cout << sum << endl;
}
