#include <bits/stdc++.h>
using namespace std;
const int N_MAX = 2000;
int num_people = 0;
vector<int> children[N_MAX];
string names[N_MAX];
int add_child(int x, string name) {
  if (x != -1) children[x].push_back(num_people);
  names[num_people++] = name;
  return num_people - 1;
}
char* parse_name(char* s, int parent) {
  int len = 0;
  char name[20];
  while (s[len] != '.' && s[len] != ':') {
    name[len] = s[len];
    len++;
  }
  int cur_ix = add_child(parent, string(name, len));
  if (s[len] == '.') return s + len + 1;
  char* cur = s + len;
  while (cur[0] != '.') {
    cur = parse_name(cur + 1, cur_ix);
  }
  return cur + 1;
}
void parse() {
  char line[3000];
  cin.getline(line, 2000);
  parse_name(line, -1);
}
int count_awkward(int x, string const& name) {
  int awk = (names[x] == name ? 1 : 0);
  for (int i = 0; i < children[x].size(); i++) {
    awk += count_awkward(children[x][i], name);
  }
  return awk;
}
int main() {
  parse();
  int total_awk = 0;
  for (int i = 0; i < num_people; i++) total_awk += count_awkward(i, names[i]);
  total_awk -= num_people;
  cout << total_awk << '\n';
}
