#include <bits/stdc++.h>
#pragma GCC optimize "trapv"
long long int power(long long int x, long long int b) {
  long long int p = 1;
  while (b > 0) {
    if (b & 1) {
      p = p * x;
      p %= 998244353;
    }
    b >>= 1;
    x *= x;
    x %= 998244353;
  }
  return p % 998244353;
}
using namespace std;
struct ppp {
  char a;
  long long int b, c, d;
};
long long int N;
struct lex_compare {
  bool operator()(ppp p1, ppp p2) {
    if (p1.a == p2.a) {
      if (p1.b == p2.b)
        return p1.c < p2.c;
      else
        return p1.b < p2.b;
    } else {
      return p1.a < p2.a;
    }
  }
};
long long int n, m, k;
bool comp(pair<long long int, long long int> p1,
          pair<long long int, long long int> p2) {
  if (p1.first == p2.first)
    return p1.second < p2.second;
  else
    return p1.first < p2.first;
}
long long int ans = 0;
map<string, long long int> m2;
void dfs(long long int src, long long int par, map<long long int, string> &m,
         vector<vector<long long int> > &edges) {
  long long int temp = m2[m[src]];
  for (auto i : edges[src]) {
    if (i != par) {
      dfs(i, src, m, edges);
    }
  }
  ans += m2[m[src]] - temp;
  ;
  m2[m[src]]++;
  return;
}
int main() {
  string s;
  getline(cin, s);
  long long int n = s.size();
  stack<long long int> st;
  int i = 0;
  int node = 0;
  vector<vector<long long int> > edges(10000);
  map<long long int, string> m;
  int j1 = 0, j2 = 0, j3 = 0;
  while (i < n) {
    if (s[i] == '.') {
      if (!st.empty()) st.pop();
      i++;
      continue;
    } else if (s[i] == ',') {
      i++;
      continue;
    }
    if (j1 <= i) j1 = s.find(':', i);
    if (j2 <= i) j2 = s.find('.', i);
    if (j3 <= i) j3 = s.find(',', i);
    if (j1 == -1) j1 = n;
    if (j2 == -1) j2 = n;
    if (j3 == -1) j3 = n;
    int j = min(j1, min(j2, j3));
    string temp = s.substr(i, j - i);
    if (st.size() > 0) {
      long long int par = st.top();
      edges[par].push_back(node);
    }
    if (j1 < j2 && j1 < j3) {
      st.push(node);
      m[node] = temp;
      node++;
      i = j1 + 1;
    } else if (j2 != -1 && j2 < j1 && j2 < j3) {
      m[node] = temp;
      node++;
      i = j2 + 1;
    } else {
      i = j3 + 1;
      continue;
    }
  }
  dfs(0, 0, m, edges);
  cout << ans << "\n";
  return 0;
}
