#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
using namespace std;
int t, n;
vector<int> a, b;
template <typename T>
T second(stack<T> x) {
  if (x.size() <= 1) return T();
  T y = x.top();
  x.pop();
  T a = x.top();
  x.push(y);
  return a;
}
vector<vector<int> > adjs;
vector<set<int> > adj;
vector<bool> vis;
map<int, string> mapper;
int dfs(int s, string par, int p = -1) {
  int ans = 0;
  if (mapper[s] == par) ans++;
  for (auto v : adj[s])
    if (v != p) ans += dfs(v, par, s);
  return ans;
}
int main() {
  string s;
  cin >> s;
  adj.assign(1000, set<int>());
  stack<pair<string, int> > pars;
  string c;
  int cnt = 0;
  int par[10000] = {};
  for (auto v : s) {
    if ((v < 'A' || v > 'Z') && c != "")
      pars.push(pair<string, int>(c, cnt++)), c = "";
    else if (v >= 'A' && v <= 'Z') {
      c += v;
    }
    if (v < 'A' || v > 'Z') {
      stack<pair<string, int> > s2 = pars;
      if (pars.top().first == "" || second(pars).first == "") continue;
      int f = pars.top().second;
      int s = second(pars).second;
      adj[f].insert(s);
      adj[s].insert(f);
      mapper[f] = pars.top().first;
      mapper[s] = second(pars).first;
      par[f] = s;
    }
    if (v == '.') pars.pop();
  }
  int ans = 0;
  for (int i = 0; i < ((int)(cnt)); i++) {
    vis.assign(cnt + 1, false);
    ans += dfs(i, mapper[i], par[i]) - 1;
  }
  cout << ans << endl;
}
