#include <bits/stdc++.h>
using namespace std;
long long ans;
string s, root;
stack<string> st;
map<string, int> ma;
map<string, vector<string>> g;
map<pair<string, string>, bool> vis;
int finding(string t) {
  return find_if(begin(t), end(t), [](char c) { return isalpha(c); }) -
         begin(t);
}
void dfs(string u, vector<string> foo) {
  foo.emplace_back(u);
  vis[{u, u}] = true;
  for (string v : g[u]) dfs(v, foo);
  if (g[u].empty()) {
    for (string i : foo) {
      for (string j : foo) {
        if (vis[{i, j}] || vis[{j, i}]) continue;
        vis[{i, j}] = vis[{j, i}] = true;
        ans += i.substr(finding(i), i.size()) == j.substr(finding(j), j.size());
      }
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cin >> s;
  for (char &c : s) {
    if (c == ':' || c == ',') c = ' ';
  }
  stringstream ss(s);
  while (ss >> s) {
    int cnt = 0;
    int d = s.find('.');
    if (d != -1) {
      cnt = s.size() - d;
      s = s.substr(0, d);
    }
    s = to_string(ma[s]++) + s;
    if (st.empty()) {
      st.emplace(s);
      root = s;
    } else {
      g[st.top()].emplace_back(s);
      st.emplace(s);
      while (cnt-- > 0) st.pop();
    }
  }
  dfs(root, vector<string>());
  cout << ans;
  return 0;
}
