#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:64000000")
using namespace std;
void __never(int a) { printf("\nOPS %d", a); }
char S[1024];
int i = 0, ans = 0;
string read_token() {
  string re;
  while (S[i] >= 'A' && S[i] <= 'Z') re.push_back(S[i++]);
  return re;
}
map<string, int> parse() {
  map<string, int> re;
  string cur = read_token();
  re[cur]++;
  if (S[i] == '.') {
    i++;
    return re;
  }
  {
    if (!(S[i] == ':')) {
      __never(44);
      cout.flush();
      cerr.flush();
      abort();
    }
  };
  i++;
  while (1) {
    map<string, int> tmp = parse();
    if (tmp.find(cur) != tmp.end()) ans += tmp[cur];
    map<string, int>::iterator it;
    for (it = tmp.begin(); it != tmp.end(); it++) re[it->first] += it->second;
    if (S[i] == ',')
      i++;
    else if (S[i] == '.') {
      i++;
      break;
    } else {
      if (!(false)) {
        __never(57);
        cout.flush();
        cerr.flush();
        abort();
      }
    };
  }
  return re;
}
void sol() {
  parse();
  cout << ans;
}
int main() {
  cin >> S;
  sol();
  return 0;
}
