#include <bits/stdc++.h>
using namespace std;
char str[1100];
char name[500][11];
int ans;
int ind;
int cur;
void employee() {
  int i;
  for (i = ind; str[i]; i++)
    if (str[i] == '.' || str[i] == ':') break;
  strncpy(name[cur++], str + ind, i - ind);
  name[cur - 1][i - ind] = 0;
  for (int j = cur - 2; j >= 0; j--)
    if (strcmp(name[cur - 1], name[j]) == 0) ans++;
  ind = i + 1;
  if (str[i] == '.') {
    cur--;
    return;
  }
  do {
    employee();
    ind++;
  } while (str[ind - 1] != '.');
  cur--;
}
int main() {
  cin >> str;
  employee();
  cout << ans << endl;
  return 0;
}
