#include <bits/stdc++.h>
using namespace std;
struct vertex {
  string name;
  vector<int> ch;
  int prv;
};
int ans;
vector<vertex> g;
void dfs(int s, string &name) {
  if (g[s].name == name) ans++;
  for (int i = 0; i < g[s].ch.size(); i++) dfs(g[s].ch[i], name);
}
int main() {
  string s, tmp;
  vertex vv;
  vv.prv = 0;
  int i, cur, top;
  cin >> s;
  cur = 0;
  top = 1;
  g.push_back(vv);
  for (i = 0; i < (int)s.length(); i++) {
    if (s[i] == ':' || s[i] == ',') {
      if (s[i] == ':') {
        g[cur].name = tmp;
        tmp.clear();
      }
      g[cur].ch.push_back(top);
      g.push_back(vv);
      g[top].prv = cur;
      cur = top;
      top++;
    } else if (s[i] == '.') {
      if (!tmp.empty()) {
        g[cur].name = tmp;
        tmp.clear();
      }
      cur = g[cur].prv;
    } else
      tmp.push_back(s[i]);
  }
  for (i = 0; i < top; i++) dfs(i, g[i].name);
  cout << ans - top;
}
