#include <bits/stdc++.h>
using namespace std;
const int M = 1e9 + 7;
int INF = 1e6;
long long int cnt = 0;
long long int n, m;
string s;
long long int i = 0;
void f(map<string, long long int> q) {
  string str = "";
  long long int k = 11;
  while (k--) {
    if (s[i] == '.' || s[i] == ',' || s[i] == ':')
      break;
    else
      str += s[i];
    i++;
  }
  cnt += q[str];
  map<string, long long int> dummy = q;
  if (s[i] == ':') {
    dummy[str]++;
    i++;
    f(dummy);
  }
  while (s[i] == ',') {
    i++;
    f(dummy);
  }
  if (s[i] == '.') {
    i++;
    return;
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long int j, t, k, x, y, z, N;
  cin >> s;
  map<string, long long int> of;
  f(of);
  cout << cnt;
  return 0;
}
