#include <bits/stdc++.h>
using namespace std;
int ans;
bool call[2000];
string s;
int process(int x, string q) {
  int i;
  string name;
  for (i = x; isalpha(s[i]); i++) name += s[i];
  if (name == q) ans++;
  if (s[i] == '.') return i;
  while (1) {
    if (i < (int)s.size() - 1 && s[i + 1] == '.') {
      call[x] = true;
      return i + 1;
    }
    if (!call[x]) process(i + 2 - (s[i] == ':'), name);
    i = process(i + 2 - (s[i] == ':'), q);
  }
  return -1;
}
int main() {
  cin >> s;
  process(0, "");
  cout << ans << endl;
  return 0;
}
