#include <bits/stdc++.h>
using namespace std;
char s[1010];
map<string, int> mp;
int l;
int pos = 0;
int ans = 0;
void dfs() {
  if (pos >= l) return;
  char tmp[15];
  int id = 0;
  for (; pos < l; pos++) {
    if (s[pos] == ':') {
      tmp[id] = 0;
      mp[tmp]++;
      pos++;
      dfs();
    } else if (s[pos] == '.') {
      tmp[id] = 0;
      if (s[pos - 1] != '.') mp[tmp]++;
      mp[tmp]--;
      ans += mp[tmp];
      return;
    } else if (s[pos] == ',') {
      pos++;
      dfs();
    } else
      tmp[id++] = s[pos];
  }
}
int main() {
  scanf("%s", s);
  l = strlen(s);
  dfs();
  printf("%d\n", ans);
  return 0;
}
