#include <bits/stdc++.h>
using namespace std;
char cc[1100];
int st;
map<string, int> m;
int ret = 0;
void get_tree() {
  string k;
  k += cc[st];
  while (cc[st + 1] != ':' && cc[st + 1] != '.') k += cc[++st];
  for (map<string, int>::iterator it = m.begin(); it != m.end(); ++it)
    if (it->first == k) ret += it->second;
  m[k] = m[k] + 1;
  if (cc[st + 1] == '.') {
    st++;
    m[k] = m[k] - 1;
    return;
  }
  if (cc[st + 1] == ':') {
    do {
      st += 2;
      get_tree();
    } while (cc[st + 1] != '.');
  }
  m[k] = m[k] - 1;
  st++;
}
int main() {
  cin.getline(cc, 1050);
  get_tree();
  cout << ret << endl;
  return 0;
}
