#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ii = pair<int, int>;
using pll = pair<ll, ll>;
string to_string(char s) { return "\'" + string(1, s) + "\'"; }
string to_string(string s) { return "\"" + s + "\""; }
template <typename T>
string to_string(vector<T>);
template <typename T>
string to_string(set<T>);
template <typename U, typename V>
string to_string(map<U, V>);
template <typename U, typename V>
string to_string(pair<U, V> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename T>
string to_string(vector<T> v) {
  string s = "[ ";
  for (auto e : v) s += to_string(e) + " ";
  s += "]";
  return s;
  ;
}
template <typename T>
string to_string(set<T> v) {
  string s = "[ ";
  for (auto e : v) s += to_string(e) + " ";
  s += "]";
  return s;
  ;
}
template <typename U, typename V>
string to_string(map<U, V> v) {
  string s = "[ ";
  for (auto e : v) s += to_string(e) + " ";
  s += "]";
  return s;
  ;
}
const int N = 1010;
char buf[N];
vector<int> adj[N];
vector<string> data;
string desc;
int n, itr;
int parseNode() {
  string root = "";
  while (desc[itr] != ':' && desc[itr] != '.') root += desc[itr++];
  int nodeID = n++;
  data.push_back(root);
  while (desc[itr] != '.') {
    itr++;
    adj[nodeID].push_back(parseNode());
  }
  itr++;
  return nodeID;
}
int freq(int u, string s) {
  int res = (data[u] == s);
  for (int v : adj[u]) res += freq(v, s);
  return res;
}
int solve(int u) {
  int res = 0;
  for (int v : adj[u]) res += freq(v, data[u]);
  for (int v : adj[u]) res += solve(v);
  return res;
}
int main() {
  scanf("%s", buf);
  desc = string(buf);
  n = itr = 0;
  int root = parseNode();
  ;
  ;
  for (int i = 0; i < n; i++)
    ;
  for (int i = 0; i < n; i++)
    ;
  printf("%d\n", solve(root));
}
