#include <bits/stdc++.h>   using namespace std;   const int MAXN = 10086;   struct Node {     string name;     vector<Node *> son;   };   char str[MAXN];   int ans;   void build(Node *&root, int &pos) {     if (str[pos] == 0) {       root = NULL;       return;     }     string name =   ;     for (; str[pos] !=  .  && str[pos] !=  : ;) {       name += str[pos++];     }     root = new Node();     root->name = name;     if (str[pos] ==  : ) {       do {         pos++;         Node *son;         build(son, pos);         if (son != NULL) root->son.push_back(son);       } while (str[pos] !=  . );     }     pos++;   }   void dfs(Node *root, map<string, int> &mp) {     if (root == NULL) return;     mp[root->name]++;     for (vector<Node *>::iterator it = root->son.begin(); it != root->son.end();          it++) {       map<string, int> _mp;       dfs(*it, _mp);       ans += _mp[root->name];       for (map<string, int>::iterator mit = _mp.begin(); mit != _mp.end(); mit++)         mp[mit->first] += mit->second;     }   }   int main() {     while (~scanf( %s , str)) {       Node *root;       int pos = 0;       build(root, pos);       ans = 0;       map<string, int> mp;       dfs(root, mp);       printf( %d n , ans);     }     return 0;   }   