#include <bits/stdc++.h>
using namespace std;
const int di[] = {-1, 0, 1, 0};
const int dj[] = {0, 1, 0, -1};
const long long MOD = 1e9 + 7;
const long long INF = 1e9;
string s;
vector<int> parent(1000, -1);
int nd = 0, r = 0;
vector<string> name(1000);
int a = 0, b = -1;
void add(int prnt) {
  a = ++b;
  while (isalpha(s[b])) b++;
  int ci = nd++;
  parent[ci] = prnt;
  name[ci] = s.substr(a, b - a);
  while (s[b] != '.') add(ci);
  b++;
}
int main() {
  ios::sync_with_stdio(false), cin.tie(0);
  cin >> s;
  while (b < (int)s.length()) {
    a = ++b;
    while (isalpha(s[b])) b++;
    int ci = nd++;
    name[ci] = s.substr(a, b);
    while (s[b] != '.') add(ci);
    b++;
  }
  for (int i = 0; i < nd; i++) {
    int cur = parent[i];
    while (cur != -1) {
      if (name[cur] == name[i]) r++;
      cur = parent[cur];
    }
  }
  cout << r << endl;
  cin.ignore(), cin.get();
}
