#include <bits/stdc++.h>
using namespace std;
class Node {
 public:
  vector<Node*> children;
  vector<pair<string, int> > names;
  string name;
  int ans;
  Node(string& line) {
    ans = 0;
    int r = 1;
    while (line[r] != ':' && line[r] != '.' && line[r] != ',') {
      r++;
    }
    name = line.substr(0, r);
    line = line.substr(r);
    while (true) {
      if (line[0] == ':') {
        line = line.substr(1);
        add_node(line);
      } else if (line[0] == '.') {
        for (int i = 0; i < (int)children.size(); ++i) {
          ans += children[i]->ans;
        }
        for (int i = 0; i < (int)names.size(); ++i) {
          if (name == names[i].first) {
            ans += names[i].second;
            break;
          }
        }
        line = line.substr(1);
        return;
      } else if (line[0] == ',') {
        line = line.substr(1);
        add_node(line);
      }
    }
  }
  void add_node(string& line) {
    Node* node = new Node(line);
    children.push_back(node);
    for (int i = 0, j = 0; i < (int)node->names.size(); ++i) {
      bool found = false;
      for (j = 0; j < (int)names.size(); ++j) {
        if (names[j].first == node->names[i].first) {
          found = true;
          break;
        }
      }
      if (found) {
        names[j].second += node->names[i].second;
      } else {
        names.push_back(pair<string, int>(node->names[i]));
      }
    }
    bool found = false;
    for (int i = 0; i < (int)names.size(); ++i) {
      if (node->name == names[i].first) {
        found = true;
        names[i].second++;
        break;
      }
    }
    if (!found) {
      names.push_back(pair<string, int>(node->name, 1));
    }
  }
};
int main() {
  string input;
  cin >> input;
  Node head(input);
  cout << head.ans << endl;
  return 0;
}
