#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  string s;
  cin >> s;
  map<string, int> hash;
  stack<string> stc;
  int count = 0;
  string s1 = "";
  string p = "";
  for (int i = 0; i < s.length() - 1; i++) {
    if (s[i] >= 'A' && s[i] <= 'Z') {
      if (s[i + 1] == '.' || s[i] == ',') {
        p += s[i];
        p += ':';
      } else {
        p += s[i];
      }
    } else if (s[i] == ':' || s[i] == '.' || s[i] == ',') {
      p += s[i];
    }
  }
  for (int i = 0; i < p.length(); i++) {
    if (p[i] == '.') {
      string cur = stc.top();
      if (hash[cur] > 1) {
        count += (hash[cur] - 1);
      }
      stc.pop();
      hash[cur] -= 1;
    } else if (p[i] == ',') {
    } else if (p[i] == ':') {
      stc.push(s1);
      if (hash.find(s1) == hash.end()) {
        hash.insert({s1, 1});
      } else {
        hash[s1] += 1;
      }
      s1 = "";
    } else {
      s1 += p[i];
    }
  }
  cout << count << endl;
  return 0;
}
