#include <bits/stdc++.h>
using namespace std;
int main() {
  int i, j, k, l, n, m;
  string in, s;
  vector<string> stk;
  {
    cin >> in;
    stk.clear();
    n = 0;
    s = "";
    for (i = 0; i < ((int)in.size()); i++) {
      if (isalpha(in[i]))
        s += in[i];
      else if (in[i] == ':') {
        stk.push_back(s);
        s = "";
      } else if (in[i] == '.') {
        if (in[i - 1] != '.') {
          for (j = 0; j < ((int)stk.size()); j++)
            if (stk[j] == s) n++;
        } else {
          for (j = 0; j < ((int)stk.size()) - 1; j++)
            if (stk[j] == stk[((int)stk.size()) - 1]) n++;
          stk.pop_back();
        }
        s = "";
      } else
        s = "";
    }
    cout << n << endl;
  }
  return 0;
}
