#include <bits/stdc++.h>
using namespace std;
const int INT = int(1e5) + 5;
const int INF = int(1e9) + 7;
inline void boost() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}
vector<pair<string, int> > x;
vector<string> mas;
int main() {
  boost();
  string a;
  cin >> a;
  int nach = -1;
  string st = "";
  for (int i = 0; i < a.size(); i++) {
    if (a[i] >= 'A' && a[i] <= 'Z') {
      if (nach == -1) {
        nach = i;
      }
      st += a[i];
    } else {
      if (nach != -1) {
        x.push_back(make_pair(st, mas.size()));
        nach = -1;
        mas.push_back(st);
        st = "";
      }
      st += a[i];
      mas.push_back(st);
      st = "";
    }
  }
  int ans = 0;
  for (int i = x.size() - 1; i >= 1; i--) {
    string oo = x[i].first;
    int pos = x[i].second;
    int sum = 0;
    int po = 0;
    for (int j = pos - 1; j >= 0; j--) {
      if (mas[j] == ".") {
        po++;
      } else {
        sum += max(po - 1, 0);
        if (mas[j] == ":") {
          if (sum >= 1) {
            sum--;
          } else {
            if (mas[j - 1] == oo) {
              ans++;
            }
          }
        }
        po = 0;
      }
    }
  }
  cout << ans;
  return 0;
}
