#include <bits/stdc++.h>
using namespace std;
char s[10005];
int sz, ans;
map<string, int> seen;
int dfs(int len, int depth) {
  if (len == sz) return len;
  int i;
  string aux = "";
  char op;
  for (i = len; s[i]; ++i) {
    if (s[i] == '.') {
      ans += seen[aux];
      return i;
    } else if (s[i] == ':' || s[i] == ',') {
      seen[aux]++;
      i = dfs(i + 1, depth + 1);
      seen[aux]--;
    } else
      aux += s[i];
  }
}
int main() {
  scanf("%s", s);
  sz = strlen(s);
  ans = 0;
  dfs(0, 0);
  printf("%d\n", ans);
  return 0;
}
