#include <bits/stdc++.h>
using namespace std;
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  std::cerr << name << " : " << arg1 << '\n';
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ',');
  std::cerr.write(names, comma - names) << " : " << arg1 << " | ";
  __f(comma + 1, args...);
}
int ans = 0;
pair<string, int> getname(string a, int startindex) {
  string b = "";
  int i = startindex;
  while (i < (int)a.length()) {
    if (a[i] == '.' || a[i] == ',' || a[i] == ':') {
      break;
    } else {
      b += a[i];
    }
    i++;
  }
  return make_pair(b, i);
}
void solve(string a, vector<string> current, int curr) {
  if ((int)a.length() == curr) {
    return;
  }
  pair<string, int> tmp = getname(a, curr);
  curr = tmp.second;
  int f = 0;
  if (tmp.first != "") {
    __f("tmp.F", tmp.first);
    current.push_back(tmp.first);
    f = 1;
  }
  if (a[curr] == '.') {
    curr++;
    int i = (int)current.size() - 2;
    while (i >= 0) {
      if (current[i] == current[(int)current.size() - 1]) {
        ans++;
      }
      i--;
    }
    current.pop_back();
    solve(a, current, curr);
  } else if (a[curr] == ':') {
    curr++;
    solve(a, current, curr);
  } else if (a[curr] == ',') {
    curr++;
    solve(a, current, curr);
  }
}
signed main() {
  std::ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  string a;
  cin >> a;
  vector<string> empty;
  solve(a, empty, 0);
  cout << ans;
  return 0;
}
