#include <bits/stdc++.h>
using namespace std;
string s;
int len, ans, tot, p;
map<string, int> Map[1010];
int build() {
  if (p == len) return -1;
  if (s[p] == '.') {
    p++;
    return -1;
  }
  string x;
  int id = tot++;
  while (p < len && isalpha(s[p])) {
    x.push_back(s[p]);
    p++;
  }
  Map[id][x]++;
  if (s[p] == '.') {
    p++;
    return id;
  }
  while (s[p] != '.') {
    p++;
    int cid = build();
    if (cid != -1) {
      ans += Map[cid][x];
      for (map<string, int>::iterator it = Map[cid].begin();
           it != Map[cid].end(); it++) {
        Map[id][it->first] += it->second;
      }
    }
  }
  p++;
  return id;
}
int main() {
  cin >> s;
  len = s.length();
  build();
  cout << ans << endl;
  return 0;
}
