#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:16777216")
using namespace std;
int n, k;
char s[1001];
string name[1000];
vector<int> g[1000];
bool used[1000];
string readName() {
  string ret;
  while (isalpha(s[k])) ret += s[k++];
  return ret;
}
vector<int> get() {
  if (s[k] == ':') k++;
  vector<int> ret;
  for (;;) {
    if (s[k] == '.' || s[k] == 0) {
      k++;
      break;
    }
    int pos = n++;
    name[pos] = readName();
    ret.push_back(pos);
    g[pos] = get();
    if (s[k] == ',') k++;
  }
  return ret;
}
int dfs(int v, const string& nm) {
  int ret = (name[v] == nm);
  for (int i = 0, _n = ((int)((g[v]).size())); i < _n; ++i)
    ret += dfs(g[v][i], nm);
  return ret;
}
void solution() {
  gets(s);
  get();
  int ret = 0;
  for (int i = 0, _n = (n); i < _n; ++i) ret += dfs(i, name[i]) - 1;
  printf("%d\n", ret);
}
int main() {
  solution();
  return 0;
}
