#include <bits/stdc++.h>
using namespace std;
struct Node {
  string name;
  vector<Node*> sub;
};
Node node[1010];
int pt, ans, pbuf, len;
char buf[1010];
Node* New() {
  node[pt].name = "";
  node[pt].sub.clear();
  return node + pt++;
}
string getName() {
  string s = "";
  while (pbuf < len && buf[pbuf] != '.' && buf[pbuf] != ':')
    s = s + buf[pbuf++];
  return s;
}
Node* Build() {
  Node* pn = New();
  pn->name = getName();
  if (buf[pbuf] == '.') {
    pbuf++;
    return pn;
  }
  if (buf[pbuf] == ':') {
    pbuf++;
    pn->sub.push_back(Build());
    while (buf[pbuf] == ',') {
      pbuf++;
      pn->sub.push_back(Build());
    }
    if (buf[pbuf] == '.') {
      pbuf++;
      return pn;
    } else {
      while (1) puts("error1");
    }
  }
  while (1) puts("error2");
  return NULL;
}
int DFS2(Node* pn, string s);
void DFS1(Node* pn) {
  for (int i = 0; i < pn->sub.size(); ++i) {
    ans += DFS2(pn->sub[i], pn->name);
  }
  for (int i = 0; i < pn->sub.size(); ++i) {
    DFS1(pn->sub[i]);
  }
}
int DFS2(Node* pn, string s) {
  int res = 0;
  if (pn->name == s) res++;
  for (int i = 0; i < pn->sub.size(); ++i) {
    res += DFS2(pn->sub[i], s);
  }
  return res;
}
int main() {
  while (scanf("%s", buf) == 1) {
    pbuf = pt = 0;
    ans = 0;
    len = strlen(buf);
    Node* root = Build();
    DFS1(root);
    printf("%d\n", ans);
  }
  return 0;
}
