#include <bits/stdc++.h>
using namespace std;
const int days[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
const int dx4[] = {-1, 0, 1, 0}, dy4[] = {0, 1, 0, -1};
const int dx8[] = {-1, -1, -1, 0, 1, 1, 1, 0},
          dy8[] = {-1, 0, 1, 1, 1, 0, -1, -1};
const int dxk[] = {2, 1, -1, -2, -2, -1, 1, 2},
          dyk[] = {1, 2, 2, 1, -1, -2, -2, -1};
const int dxh[] = {0, 1, 1, 0, -1, -1}, dyh[] = {1, 1, 0, -1, -1, 0};
const double PI = acos(-1.0);
const int INF = 1000000000;
const double EPS = 1e-11;
string a[1000], s;
int ret, top, n;
int main() {
  cin >> s;
  n = s.length();
  ret = 0;
  top = 0;
  string name = "";
  for (int i = 0; i < (int)(n); ++i) {
    if (isalpha(s[i])) {
      name += s[i];
      continue;
    }
    if (s[i] == ':' || s[i] == ',') {
      if (name != "") {
        a[top++] = name;
        name = "";
      }
      continue;
    }
    if (name != "") {
      a[top++] = name;
      name = "";
    }
    for (int j = 0; j < (int)(top - 1); ++j)
      if (a[j] == a[top - 1]) ++ret;
    --top;
  }
  cout << ret << endl;
  return 0;
}
