#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
signed main() {
  string s;
  cin >> s;
  long long ans = 0;
  long long same = 1;
  vector<long long> sa(0);
  for (long long i = 0; i < s.size() - 1; i++) {
    if (s[i] == s[i + 1]) {
      same++;
      continue;
    }
    if (s[i] != s[i + 1]) {
      if (same % 3 != 0) sa.push_back(same % 3);
      if (same % 3 == 0)
        ans += 2 * (same / 3);
      else
        ans += (2 * (same / 3) + 1);
      same = 1;
    }
  }
  if (same % 3 != 0) sa.push_back(same % 3);
  if (same % 3 == 0)
    ans += 2 * (same / 3);
  else
    ans += (2 * (same / 3) + 1);
  for (long long i = 0; i < sa.size() - 1; i++) {
    if (sa[i] == 2 && sa[i + 1] == 2) {
      ans++;
      sa[i] = 1;
      sa[i + 1] = 1;
    }
  }
  cout << ans << endl;
}
