#include <bits/stdc++.h>
using namespace std;
string s;
string name[1010];
vector<int> adj[1010];
int n, tot, ans, st[1010], en[1010];
void dfs(int x, string cur) {
  int j = cur.find(":");
  if (j == string::npos) j = cur.find(".");
  name[x] = cur.substr(0, j);
  cur.erase(0, j + 1);
  st[x] = ++tot;
  for (;;) {
    if (cur.size() == 0) break;
    string next = "";
    int st = 0;
    for (int i = 0; i < cur.size(); i++) {
      next += cur[i];
      if (i == 0 || isalpha(cur[i]) && !isalpha(cur[i - 1]))
        st++;
      else if (cur[i] == '.') {
        st--;
        if (st == 0) {
          cur.erase(0, i + 2);
          break;
        }
      }
    }
    dfs(++n, next);
  }
  en[x] = ++tot;
}
int main() {
  cin >> s;
  n = 1;
  tot = ans = 0;
  dfs(1, s);
  for (int i = 1; i <= n; i++)
    for (int j = i + 1; j <= n; j++)
      if (name[i] == name[j] &&
          (st[i] < st[j] && en[j] < en[i] || st[j] < st[i] && en[i] < en[j]))
        ans++;
  cout << ans << endl;
  return 0;
}
