#include <bits/stdc++.h>
using namespace std;
const int MX = (1009);
string buffer;
string name[MX];
int n, pos = 0;
vector<int> v[MX];
map<string, int> dp;
void dfs(int x) {
  while (isalpha(buffer[pos])) name[x].push_back(buffer[pos++]);
  if (buffer[pos++] == '.') return;
  while (1) {
    if (isalpha(buffer[pos])) {
      v[x].push_back(++n);
      dfs(n);
    }
    if (buffer[pos++] == '.') return;
  }
}
int ans = 0, head;
void go(int x) {
  if (x != head && name[head] == name[x]) ++ans;
  for (auto nxt : v[x]) go(nxt);
}
int main() {
  cin >> buffer;
  buffer += "#";
  dfs(++n);
  for (int j = 1; j <= n; j++) {
    head = j;
    go(j);
  }
  cout << ans << endl;
}
