#include <bits/stdc++.h>
using namespace std;
vector<string> q;
string s;
int ans;
void calc() {
  for (int i = 0; i < q.size(); i++)
    if (q[i] == s) ans++;
}
int main() {
  char ch;
  while (cin >> ch) {
    if (ch >= 'A' && ch <= 'Z')
      s.push_back(ch);
    else if (ch == ':') {
      calc();
      q.push_back(s);
      s.clear();
    } else if (ch == '.') {
      if (s.size()) {
        calc();
        q.push_back(s);
        s.clear();
      }
      q.pop_back();
    }
  }
  cout << ans;
  return 0;
}
