#include <bits/stdc++.h>
using namespace std;
const int N = 1100;
const int MAXN = int(1e6) + 100;
const long long mod = int(1e9) + 7;
int solution();
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  return solution();
}
string s, name[N];
int pos, last, cnt;
vector<int> g[N];
bool u[N];
void parse(int parent) {
  string cur_name = "";
  for (; pos < s.size(); pos++) {
    if (s[pos] == ':') {
      pos++;
      g[parent].push_back(++last);
      name[last] = cur_name;
      parse(last);
      cur_name = "";
    } else if (s[pos] == '.') {
      if (cur_name != "") {
        g[parent].push_back(++last);
        name[last] = cur_name;
        cur_name = "";
      } else {
        return;
      }
    } else if (s[pos] != ',') {
      cur_name += s[pos];
    }
  }
}
void dfs(int x, int root) {
  if (x != root && name[x] == name[root]) {
    cnt++;
  }
  u[x] = true;
  for (auto to : g[x]) {
    if (!u[to]) dfs(to, root);
  }
}
int solution() {
  cin >> s;
  parse(0);
  for (int i = 1; i <= last; i++) {
    dfs(i, i);
    memset(u, 0, sizeof u);
  }
  cout << cnt;
  return 0;
}
