#include <bits/stdc++.h>
using namespace std;
const int maxn = 1123;
char ch;
int n, ans;
string s[maxn];
int main() {
  while (cin >> ch) {
    if (ch == '.') {
      for (int(i) = (0); (i) <= ((n)-1); (i)++)
        if (s[i] == s[n]) ans++;
      s[n] = "";
      n--;
    } else if (ch == ':' || ch == ',')
      n++;
    else
      s[n] += ch;
  }
  cout << ans;
}
