#include <bits/stdc++.h>
using namespace std;
const int Mod = (int)1e9 + 7;
const int MX = 1073741822;
const long long MXLL = 4e18;
const int Sz = 1110111;
inline void Read_rap() {
  ios_base ::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}
inline void randomizer3000() {
  unsigned int seed;
  asm("rdtsc" : "=A"(seed));
  srand(seed);
}
void files(string problem) {
  if (fopen((problem + ".in").c_str(), "r")) {
    freopen((problem + ".in").c_str(), "r", stdin);
    freopen((problem + ".out").c_str(), "w", stdout);
  }
}
void localInput(const char in[] = "s") {
  if (fopen(in, "r")) {
    freopen(in, "r", stdin);
  } else
    cerr << "Warning: Input file not found" << endl;
}
map<string, int> cnt;
int ans;
void dfs(string s) {
  string name;
  vector<string> g;
  bool endname = 0;
  int bal = 0;
  for (int i = 0; i < s.size() - 1; i++) {
    if (s[i] == ':' && !endname) {
      bal++;
      g.push_back("");
      endname = 1;
      continue;
    }
    if (!endname)
      name.push_back(s[i]);
    else {
      if (s[i] == ',' && bal == 0) {
        g.push_back("");
        bal++;
        continue;
      }
      if (s[i] == ':' || s[i] == ',') bal++;
      if (s[i] == '.') bal--;
      g.back().push_back(s[i]);
    }
  }
  ans += cnt[name];
  cnt[name]++;
  if ((int)(g.size()) && !(int)(g.back().size())) g.pop_back();
  for (auto to : g) {
    dfs(to);
  }
  cnt[name]--;
}
int main() {
  Read_rap();
  string s;
  cin >> s;
  dfs(s);
  cout << ans;
  return 0;
}
