#include <bits/stdc++.h>
using namespace std;
char str[1234];
char word[21];
int slen;
int res;
void solve(char *s, int l) {
  int r = 0;
  int len = strlen(s);
  int k = 2, t = 0;
  for (int i = l; i < slen; i++) {
    if (str[i] == '.')
      k--;
    else if (str[i] == ':' || str[i] == ',')
      k++;
    else
      word[t++] = str[i];
    if (t != 0 && (str[i] == '.' || str[i] == ':' || str[i] == ',')) {
      word[t] = '\0';
      if (t != len) {
        t = 0;
        continue;
      }
      bool flag = true;
      for (int j = 0; j < t; j++) {
        if (s[j] != word[j]) {
          flag = false;
          break;
        }
      }
      if (flag) res++;
      t = 0;
    }
    if (k == 0) break;
  }
}
int main() {
  gets(str);
  slen = strlen(str);
  res = 0;
  char ss[22], ts[22], cc;
  for (int i = slen - 1; i >= 0; i--) {
    if (str[i] == ':') {
      cc = 0;
      for (int j = i - 1; j >= 0; j--) {
        if (str[j] == '.' || str[j] == ':' || str[j] == ',') break;
        ts[cc++] = str[j];
      }
      for (int j = 0; j < cc; j++) {
        ss[j] = ts[cc - j - 1];
      }
      ss[cc] = '\0';
      solve(ss, i + 1);
    }
  }
  printf("%d\n", res);
  return 0;
}
