#include <bits/stdc++.h>
using namespace std;
int main() {
  string x, arr[100];
  int ind = 0, ans = 0;
  cin >> x;
  for (unsigned int a = 0; a < x.length(); a++) {
    if (x[a] == '.') {
      for (int i = 0; i < ind; i++)
        if (arr[i] == arr[ind]) ans++;
      arr[ind] = "";
      ind--;
    } else if (x[a] == ':' || x[a] == ',')
      ind++;
    else
      arr[ind] += x[a];
  }
  cout << ans << endl;
}
