#include <bits/stdc++.h>
using namespace std;
struct node {
  string name;
  vector<struct node*> subs;
};
typedef struct node* NODE;
int ans = 0;
void dfs(NODE root, unordered_map<string, int> visited) {
  string emp_name = root->name;
  vector<NODE> children = root->subs;
  ans += visited[emp_name];
  visited[emp_name]++;
  for (auto it : children) {
    dfs(it, visited);
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  string s;
  cin >> s;
  int n = s.length();
  stack<NODE> stk;
  int p = 0;
  string word;
  while (s[p] >= 'A' && s[p] <= 'Z') {
    word += s[p];
    p++;
  }
  NODE root = new struct node;
  root->name = word;
  stk.push(root);
  while (p < n) {
    string t;
    NODE recent = stk.top();
    if (s[p] == ',' || s[p] == ':') {
      p++;
      while (s[p] >= 'A' && s[p] <= 'Z' && p < n) {
        t += s[p];
        p++;
      }
      NODE child = new struct node;
      child->name = t;
      stk.push(child);
      recent->subs.push_back(child);
    }
    if (s[p] == '.') {
      stk.pop();
      p++;
    }
  }
  unordered_map<string, int> visited;
  dfs(root, visited);
  cout << ans;
  return 0;
}
