#include <bits/stdc++.h>
using namespace std;
const int maxn = 1010;
int n = 1;
string str, peo[maxn];
int main() {
  cin >> str;
  int ans = 0;
  for (int i = 0; i < (int)str.length(); i++) {
    if ('A' <= str[i] && str[i] <= 'Z')
      peo[n] += str.substr(i, 1);
    else if (str[i] == ':' || str[i] == ',')
      n++;
    else if (str[i] == '.') {
      for (int j = 1; j < n; j++)
        if (peo[j] == peo[n]) ans++;
      peo[n--] = "";
    }
  }
  cout << ans << endl;
  return 0;
}
