#include <bits/stdc++.h>
using namespace std;
string s;
int main() {
  cin >> s;
  long long int ans = 0;
  vector<string> v;
  string temp = "";
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == '.' && v.size() != 0) {
      for (int i = 0; i < v.size(); i++) {
        if (temp == v[i]) ++ans;
      }
      if (temp == "") v.pop_back();
      temp = "";
      continue;
    }
    if (s[i] == ':') {
      for (int i = 0; i < v.size(); i++) {
        if (temp == v[i]) ++ans;
      }
      v.push_back(temp);
      temp = "";
      continue;
    }
    if (s[i] != ',') temp += s[i];
  }
  cout << ans << endl;
}
