#include <bits/stdc++.h>
using namespace std;
int ans, idx;
string s;
map<string, int> cnt;
void cal() {
  int tp = idx;
  while (isalpha(s[idx])) idx++;
  string tmp = s.substr(tp, idx - tp);
  ans += cnt[tmp];
  cnt[tmp]++;
  while (s[idx++] ^ '.') cal();
  cnt[tmp]--;
}
int main() {
  while (cin >> s) {
    cnt.clear();
    ans = idx = 0;
    cal();
    cout << ans << endl;
  }
}
