#include <bits/stdc++.h>
const int N = 100010;
const int inf = 0x3f3f3f3f;
using namespace std;
char s[N];
int main() {
  scanf("%s", s);
  stack<string> sk;
  map<string, int> h;
  int l = strlen(s), ret = 0;
  for (int i = 0, j = -1; i < l; i = j + 1) {
    if (s[j + 1] <= 'Z' && s[j + 1] >= 'A') {
      string str = "";
      while (s[j + 1] <= 'Z' && s[j + 1] >= 'A') str += s[j + 1], j++;
      ret += h[str];
      h[str]++;
      sk.push(str);
    } else if (s[j + 1] == ',')
      j++;
    else if (s[j + 1] == ':')
      j++;
    else if (s[j + 1] == '.')
      h[sk.top()]--, sk.pop(), j++;
  }
  cout << ret << endl;
  return 0;
}
