#include <bits/stdc++.h>
using namespace std;
map<string, int> mp;
stack<string> st;
string s, ss;
bool ok;
int ans;
int main() {
  ios::sync_with_stdio(0);
  cin >> s;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == '.' && ss != "" || s[i] == ':' && ss != "")
      st.push(ss), ans += mp[ss]++;
    if (s[i] == ':') {
      ss.clear();
    } else if (s[i] == '.') {
      mp[st.top()]--;
      st.pop();
      ss = "";
    } else if (s[i] == ',') {
    } else {
      ss += s[i];
    }
  }
  cout << ans << endl;
  return 0;
}
