#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1.0);
const double EPS = 1e-9;
const int OO = 210000000;
string s;
int cur, len, fa[1010], p;
string a[1010];
bool capital(char x) { return (x >= 'A' && x <= 'Z'); }
void dfs(int f) {
  if (s[p] == '.' || p >= len) return;
  cur++;
  string tmp = "";
  while (!capital(s[p]) && p < len) p++;
  while (capital(s[p]) && p < len) tmp += s[p++];
  a[cur] = tmp;
  fa[cur] = f;
  if (s[p] == '.' || p >= len) return;
  while (!capital(s[p]) && p < len) p++;
  int tmp1 = cur;
  while (p < len) {
    if (s[p] != '.') dfs(tmp1);
    if (s[++p] == '.') return;
  }
}
int main() {
  char s1[1010];
  while (scanf("%s", s1) == 1) {
    len = strlen(s1);
    s = s1;
    cur = p = 0;
    memset(fa, 0, sizeof(fa));
    dfs(0);
    int ans = 0;
    for (int i = 1; i <= cur; i++) {
      int tmp = i;
      while (fa[tmp]) {
        tmp = fa[tmp];
        if (tmp && a[tmp] == a[i]) {
          ans++;
        }
      }
    }
    printf("%d\n", ans);
  }
  return (0);
}
