#include <bits/stdc++.h>
using namespace std;
template <class T, class L>
bool smax(T &x, L y) {
  return x < y ? (x = y, 1) : 0;
}
template <class T, class L>
bool smin(T &x, L y) {
  return y < x ? (x = y, 1) : 0;
}
const int maxn = 1e5 + 17;
string s;
int ans, f[maxn];
int count(int st, int en, string &p) {
  int k = 0, cnt = 0;
  for (int i = 1; i < p.size(); i++) {
    while (k && p[i] != p[k]) k = f[k];
    if (p[k] == p[i]) k++;
    f[i + 1] = k;
  }
  k = 0;
  for (int i = st; i < en; i++) {
    while (k && s[i] != p[k]) k = f[k];
    if (p[k] == s[i]) k++;
    if (k == p.size()) {
      cnt += !isalpha(s[i + 1]) && !isalpha(s[i - k]), k = f[k];
    }
  }
  return cnt;
}
int dfs(int st) {
  int en = st;
  while (s[en] != '.' && s[en] != ':') en++;
  if (s[en] == '.') return en + 1;
  string me = s.substr(st, en - st);
  while (s[en] != '.') {
    int h = ++en;
    en = dfs(h);
    ans += count(h, en, me);
  }
  return en + 1;
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0);
  cin >> s;
  dfs(0);
  cout << ans << '\n';
  return 0;
}
