#include <bits/stdc++.h>
using namespace std;
long long int binpowmod(long long int a, long long int b, long long int m) {
  a %= m;
  long long int res = 1;
  while (b > 0) {
    if (b & 1) res = res * a % m;
    a = a * a % m;
    b >>= 1;
  }
  return res;
}
long long int binpow(long long int a, long long int b) {
  long long int res = 1;
  while (b > 0) {
    if (b & 1) res = res * a;
    a = a * a;
    b >>= 1;
  }
  return res;
}
long long int modInverse(long long int n, long long int p) {
  return binpowmod(n, p - 2, p);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int t, m, n, i, f = 0, j, ans = 0, k, x, r;
  string s, s1, s2;
  vector<string> v;
  cin >> s;
  s1 = "";
  k = -1;
  for (i = 0; i < s.length(); ++i) {
    if (s[i] == '.') {
      if (s1.length() != 0) {
        for (j = 0; j < k + 1; ++j) {
          if (s1 == v[j]) ans++;
        }
        s1 = "";
      } else {
        s1 = v[k];
        for (j = 0; j < k; ++j) {
          if (s1 == v[j]) ans++;
        }
        s1 = "";
        v.erase(v.begin() + k);
        k--;
      }
    } else if (s[i] == ',') {
      continue;
    } else if (s[i] == ':') {
      v.push_back(s1);
      k++;
      s1 = "";
    } else {
      s1 += s[i];
    }
  }
  cout << ans;
  return 0;
}
