#include <bits/stdc++.h>
using namespace std;
string s;
struct point {
  string s;
  int parent;
  int p;
};
point d[1001];
int main() {
  string s;
  getline(cin, s);
  int i, a, good = 1, em = 1;
  int parent = -1;
  int p = 1;
  int h = 0;
  for (i = 0; i < s.length(); i++) {
    if (s[i] >= 'A' && s[i] <= 'Z') {
      if (good) {
        a = i;
        good = 0;
      }
    } else {
      good = 1;
      if (s[i] == ':') {
        d[em].s = s.substr(a, i - a);
        d[em].parent = parent;
        d[em].p = p;
        p++;
        parent = em;
        em++;
      }
      if (s[i] == '.') {
        point f;
        f.s = s.substr(a, i - a);
        int t = 1;
        while (i + 1 < s.length() && s[i + 1] == '.') {
          t++;
          i++;
        }
        f.parent = parent;
        f.p = p;
        d[em] = f;
        while (t > 1) {
          parent = d[parent].parent;
          t--;
        }
        em++;
      }
    }
  }
  for (i = em - 1; i >= 1; i--) {
    int j = d[i].parent;
    while (j != -1) {
      if (d[i].s == d[j].s) h++;
      j = d[j].parent;
    }
  }
  printf("%d\n", h);
}
