#include <bits/stdc++.h>
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  std::cerr << name << " : " << arg1 << "\n";
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ',');
  std::cerr.write(names, comma - names) << " : " << arg1 << " | ";
  __f(comma + 1, args...);
}
std::pair<int, int> operator+(std::pair<int, int> a, std::pair<int, int> b) {
  return {a.first + b.first, a.second + b.second};
}
std::pair<long long, long long> operator+(std::pair<long long, long long> a,
                                          std::pair<long long, long long> b) {
  return {a.first + b.first, a.second + b.second};
}
std::ostream& operator<<(std::ostream& out, std::pair<int, int> a) {
  out << a.first << " " << a.second << "\n";
  return out;
}
std::ostream& operator<<(std::ostream& out, std::pair<long long, long long> a) {
  out << a.first << " " << a.second << "\n";
  return out;
}
std::istream& operator>>(std::istream& in, std::pair<int, int>& a) {
  in >> a.first >> a.second;
  return in;
}
std::istream& operator>>(std::istream& in, std::pair<long long, long long>& a) {
  in >> a.first >> a.second;
  return in;
}
long long bpow(long long x, long long v) {
  if (v == 0) return 1 % 1000000007;
  if (v % 2 == 1) return (x * bpow(x, v - 1)) % 1000000007;
  long long r = bpow(x, v / 2);
  return (r * r) % 1000000007;
}
using namespace std;
long long compute_hash(string const& s) {
  const int p = 31;
  const int m = 1e9 + 9;
  long long hash_value = 0;
  long long p_pow = 1;
  for (char c : s) {
    hash_value = (hash_value + (c - 'A' + 1) * p_pow) % m;
    p_pow = (p_pow * p) % m;
  }
  return hash_value;
}
long long og, c = 0;
vector<int> adj[100005];
unordered_map<long long, int> freq, val;
void dfs(int x, int k) {
  if (val[x] == og && k != 0) {
    c++;
  }
  for (auto i : adj[x]) {
    dfs(i, 1);
  }
}
void solve() {
  string s;
  cin >> s;
  int j = 0, a, k = 0;
  stack<int> stk;
  long long nm;
  int n = s.size();
  for (int i = 0; i < n; ++i) {
    string name;
    if (s[i] > 58) {
      k++;
      while (s[i] > 58) {
        name.push_back(s[i]);
        i++;
      }
      nm = compute_hash(name);
      freq[nm]++;
      val[k] = nm;
      stk.push(k);
    }
    if (s[i] == 46) {
      a = stk.top();
      if (stk.size() == 1) break;
      stk.pop();
      adj[stk.top()].push_back(a);
    }
  }
  for (auto i : val) {
    if (freq[i.second] > 1) {
      og = i.second;
      dfs(i.first, 0);
    }
  }
  cout << c;
}
int main() {
  std::ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  while (t--) solve();
}
