#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 10;
const int INF = 0x3f3f3f3f;
const int mod = 1e9 + 7;
const int pi = 3.1415;
char S;
int n, ans;
string s[610];
int main() {
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  ;
  while (cin >> S) {
    if (S == '.') {
      for (int i = 0; i < n; i++) {
        if (s[i] == s[n]) ans++;
      }
      s[n] = "";
      n--;
    } else if (S == ':' || S == ',')
      n++;
    else
      s[n] += S;
  }
  cout << ans << endl;
  return 0;
}
