#include <bits/stdc++.h>
using namespace std;
long long test[213456];
signed main() {
  long long n = 0, a = 0, sum = 1, ans = 0;
  string s;
  cin >> s;
  for (long long h = 1; h < s.size(); h++) {
    if (s[h - 1] == s[h]) {
      sum++;
    } else {
      if (sum % 3 == 0) {
        ans += sum / 3 * 2;
      } else {
        ans += (sum + 2) / 3 * 2 - 1;
      }
      test[a] = sum;
      sum = 1;
      a++;
    }
  }
  if (sum % 3 == 0) {
    ans += sum / 3 * 2;
  } else {
    ans += (sum + 2) / 3 * 2 - 1;
  }
  test[a] = sum;
  for (long long h = 1; h <= a; h++) {
    if (h >= 2 && test[h - 2] % 3 != 0) {
      if (test[h - 1] % 3 == 0) {
        if (test[h] % 3 != 0) {
          ans++;
        }
      }
    }
    if (test[h - 1] % 3 == 2 && test[h] % 3 == 2) {
      n++;
    } else if (n != 0) {
      n = 0;
      ans++;
    }
  }
  if (n != 0) {
    ans++;
  }
  cout << ans << endl;
}
