#include <bits/stdc++.h>
using namespace std;
int n;
vector<int> a[1111];
string name[1111];
string s;
vector<int> v;
int pos;
void dfs() {
  string nm = "";
  while (s[pos] != ':' && s[pos] != '.') nm += s[pos++];
  name[n] = nm;
  a[v.back()].push_back(n++);
  v.push_back(n - 1);
  while (s[pos] != '.') {
    ++pos;
    dfs();
    ++pos;
  }
  v.pop_back();
}
int dfs2(int v, string nm) {
  int cur = 0;
  if (name[v] == nm) cur++;
  for (int(i) = 0; (i) < ((int)a[v].size()); ++(i)) cur += dfs2(a[v][i], nm);
  return cur;
}
int main() {
  cin >> s;
  v.push_back(1000);
  dfs();
  int ans = 0;
  for (int(i) = 0; (i) < (n); ++(i)) ans += dfs2(i, name[i]) - 1;
  cout << ans << endl;
}
