#include <bits/stdc++.h>
using namespace std;
bool comp(pair<int, int> a, pair<int, int> b) {
  return (a.first == b.first) ? a.second < b.second : a.first < b.first;
}
long long int modInverse(long long int a) {
  long long int m = 1000000007;
  long long int y = 0, x = 1;
  while (a > 1) {
    long long int q = a / m;
    long long int t = m;
    m = a % m, a = t;
    t = y;
    y = x - q * y;
    x = t;
  }
  if (x < 0) x += 1000000007;
  return x;
}
long long int binpow(long long int a, long long int p) {
  if (p == 0) return 1;
  long long int ret = binpow(a, p / 2);
  ret *= ret;
  ret %= 1000000007;
  if (p % 2) {
    ret *= a;
    ret %= 1000000007;
  }
  return ret;
}
int res = 0, len;
string s;
unordered_map<string, int> dfs(int &i) {
  string t = "";
  unordered_map<string, int> temp, temp1;
  while (s[i] >= 'A' && s[i] <= 'Z') {
    t += s[i];
    i++;
  }
  temp[t]++;
  while (s[i++] != '.') {
    if (s[i] == ',') i++;
    temp1 = dfs(i);
    res += temp1[t];
    for (auto st : temp1) temp[st.first] += st.second;
  }
  return temp;
}
void solve() {
  cin >> s;
  len = s.length();
  int i = 0;
  dfs(i);
  cout << res;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  int t = 1;
  while (t--) {
    solve();
  }
}
