#include <bits/stdc++.h>
using namespace std;
struct node {
  string name;
  vector<node *> child;
};
string s, buffer;
stack<node *> st;
int c;
map<string, int> back;
void dfs(node *n) {
  if (back.count(n->name)) c += back[n->name];
  back[n->name]++;
  for (int i = 0; i < n->child.size(); ++i) dfs(n->child[i]);
  if (--back[n->name] == 0) back.erase(n->name);
}
void print(node *n, int d = 0) {
  cout << string(d, ' ') << ' ' << n->name << endl;
  for (int i = 0; i < n->child.size(); ++i) print(n->child[i], d + 1);
}
int main() {
  cin >> s;
  node *root = new node();
  st.push(root);
  for (int i = 0; i < s.length(); ++i) {
    if (isupper(s[i])) {
      st.top()->name += s[i];
    } else if (s[i] == ':' || s[i] == ',') {
      node *n = new node();
      st.top()->child.push_back(n);
      st.push(n);
    } else if (s[i] == '.') {
      st.pop();
    }
  }
  dfs(root);
  cout << c << endl;
}
