#include <bits/stdc++.h>
using namespace std;
using ll = long long;
namespace NS {
void LoopUntilZeroInpput() {
  int hogegegege = 0;
  while (cin >> hogegegege && hogegegege != 0) {
  }
}
}  // namespace NS
const char HEAD = 'H';
int main() {
  string S;
  cin >> S;
  queue<char> q;
  char prev = 'n';
  ll N = S.size();
  for (ll i = 0; i < N; ++i) {
    if (prev == 'n') {
      prev = S[i];
    } else {
      if (prev != S[i]) {
        prev = 'n';
      } else {
        q.push(prev);
        prev = S[i];
      }
    }
  }
  q.push(prev);
  q.push(HEAD);
  ll lastSize = q.size();
  prev = 'n';
  while (1) {
    char fChar = q.front();
    q.pop();
    if (fChar == HEAD) {
      if (prev != 'n') {
        q.push(prev);
      }
      if (lastSize == q.size()) {
        break;
      } else {
        lastSize = q.size();
        q.push(HEAD);
        prev = 'n';
      }
    } else {
      if (prev == 'n') {
        prev = fChar;
      } else {
        if (prev != fChar) {
          prev = 'n';
        } else {
          q.push(prev);
          prev = fChar;
        }
      }
    }
  }
  ll ans = N - q.size();
  cout << ans << endl;
}
