#include <bits/stdc++.h>
using namespace std;
string t;
vector<string> h;
int main() {
  char c;
  int ans = 0;
  while (cin >> c) {
    if (c == '.') {
      if (t == "") {
        t = h[h.size() - 1];
        h.pop_back();
      }
      for (int i = 0; i < h.size(); ++i)
        if (h[i] == t) ++ans;
      t = "";
    } else if (c == ':')
      h.push_back(t), t = "";
    else if (c != ',')
      t += c;
  }
  cout << ans << endl;
  return 0;
}
