#include <bits/stdc++.h>
using namespace std;
string s;
int p, g, z;
vector<string> a(0), b(0);
vector<int> c(0);
void rq(vector<string> q, int r) {
  int h;
  vector<string> t;
  for (int i = 0; i < q.size(); i++) {
    b.push_back(q[i]);
    c.push_back(r);
    h = 1;
    t.resize(0);
    while (h > 0) {
      i++;
      if (q[i] == ".")
        h--;
      else
        h++;
      if (h > 0) t.push_back(q[i]);
    }
    if (t.size() > 0) rq(t, c.size() - 1);
  }
}
int main() {
  cin >> s;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == '.') {
      if (p < i) a.push_back(s.substr(p, i - p));
      a.push_back(".");
      p = i + 1;
    } else if (s[i] == ',' || s[i] == ':') {
      if (p < i) a.push_back(s.substr(p, i - p));
      p = i + 1;
    }
  }
  rq(a, -1);
  for (int i = 0; i < b.size(); i++) {
    z = i;
    z = c[z];
    while (z != -1) {
      if (b[z] == b[i]) g++;
      z = c[z];
    }
  }
  cout << g;
  return 0;
}
