#include <bits/stdc++.h>
using namespace std;
int a[1001000], b[1001000];
int n;
int x[1001000], y[1001000];
map<string, int> mp;
long long ans;
void dfs() {
  string t = "";
  char ch;
  while ((ch = getchar()) && ch != ':' && ch != ',' && ch != '.') {
    t += ch;
  }
  ans += mp[t];
  mp[t]++;
  while (ch == ':' || ch == ',') {
    dfs();
    ch = getchar();
  }
  mp[t]--;
}
int main() {
  mp.clear();
  ans = 0;
  dfs();
  cout << ans << endl;
  return 0;
}
