#include <bits/stdc++.h>
using namespace std;
vector<vector<int> > M;
vector<string> R;
int ind = 0;
int rec(string s, int indice) {
  int i = s.find('.', indice), j = s.find(':', indice);
  if (j == -1 || i < j) {
    R.push_back(s.substr(indice, i - indice));
    ind++;
    return i;
  }
  R.push_back(s.substr(indice, j - indice));
  int ori = ind++;
  M[ori].push_back(ind);
  int h = j + 1;
  while (true) {
    h = rec(s, h);
    if (s[h + 1] == '.') break;
    M[ori].push_back(ind);
    h += 2;
  }
  return h + 1;
}
int ref(string s, int h) {
  int cont = (s == R[h]);
  for (int i = 0; i < M[h].size(); i++) {
    cont += ref(s, M[h][i]);
  }
  return cont;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  string s;
  cin >> s;
  M.assign(1000, vector<int>());
  rec(s, 0);
  int sum = 0;
  for (int i = 0; i < ind; i++) {
    int cont = ref(R[i], i);
    sum += (cont - 1);
  }
  cout << sum << "\n";
  return 0;
}
