#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:66777216")
using namespace std;
const int N = 3e5 + 7;
int cnt[N], nex[N][26], mean[N], en[N], del[N];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  string s;
  int n, mx = 0, ans = 0;
  for (int i = 'a'; i <= 'z'; i++) {
    mean[i] = i - 'a';
  }
  mean['.'] = 26;
  mean[','] = 27;
  mean['?'] = 28;
  mean['!'] = 29;
  mean[39] = 30;
  mean['-'] = 31;
  mean[' '] = 32;
  while (getline(cin, s)) {
    s += "-";
    n = s.size();
    int v = 0, k = 0, start = 0, med = -1, conec = -1, l = 0;
    for (int i = 0; i < n; i++) {
      if (mean[s[i]] > 25) {
        if (start != i) {
          if (conec != -1) {
            k += min(med - start + 1 + i - conec, i - start);
          } else {
            k += i - start;
          }
        }
        l = 0;
        k++;
        conec = -1;
        start = i + 1;
        v = 0;
        med = -1;
        continue;
      }
      if (med == -1) {
        if (cnt[nex[v][mean[s[i]]]] == 1 && nex[v][mean[s[i]]] != 0) {
          med = i;
        }
      } else if (med >= 0 && conec == -1) {
        if (nex[v][mean[s[i]]] == 0 && conec == -1) {
          if (en[v]) {
            conec = i - 1;
          } else {
            med = -2;
          }
        } else if (mean[s[i + 1]] > 25) {
          if (nex[v][mean[s[i]]] && en[nex[v][mean[s[i]]]]) {
            conec = i;
            for (int j = 0; j < l; j++) {
              cnt[del[j]]--;
            }
          } else {
            med = -2;
          }
        }
      }
      if (nex[v][mean[s[i]]] == 0) {
        nex[v][mean[s[i]]] = ++mx;
      }
      v = nex[v][mean[s[i]]];
      cnt[v]++;
      del[l++] = v;
      if (mean[s[i + 1]] > 25) {
        en[v] = 1;
      }
    }
    ans += k;
  }
  cout << ans;
  cin >> n;
  return 0;
}
