#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  vector<string> myStack;
  string str;
  cin >> str;
  int num = 0;
  for (int i = 0; i < str.size(); i++) {
    string check = "";
    while (i < str.length()) {
      if (str[i] == '.' || str[i] == ',' || str[i] == ':') {
        break;
      } else {
        check += str[i];
      }
      i++;
    }
    if (check.length()) {
      for (int j = 0; j < myStack.size(); j++) {
        if (myStack[j] == check) {
          num++;
        }
      }
      myStack.push_back(check);
    }
    if (str[i] == '.') {
      myStack.pop_back();
    }
  }
  cout << num;
  return 0;
}
