#include <bits/stdc++.h>
using namespace std;
struct edge {
  int counter;
  char name[105];
  vector<edge*> items;
  edge() { counter = -1; }
};
int len;
char ptr;
edge* tree = new edge();
int solve(edge* node, char name[]) {
  bool equals_node = !strcmp(node->name, name);
  if (equals_node && node->counter != -1) return node->counter;
  int ans = equals_node;
  for (unsigned i = 0; i < node->items.size(); ++i)
    ans += solve(node->items[i], name);
  if (equals_node) node->counter = ans;
  return ans;
}
int create(edge* node) {
  int ans = 0;
  while (ptr != '.' && ptr != '\n') {
    len = -1;
    edge* temp = new edge();
    do {
      temp->name[++len] = (ptr = getchar());
    } while (ptr >= 'A' && ptr <= 'Z');
    temp->name[len] = 0;
    if (len) {
      node->items.push_back(temp);
      ans += create(temp);
    }
  };
  ans += (solve(node, node->name) - 1);
  ptr = getchar();
  return ans;
}
int main() {
  printf("%d\n", create(tree));
  return 0;
}
