#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  cin >> s;
  int idx = 0;
  int ans = 0;
  int sz = s.size();
  while (idx < sz) {
    char c = s[idx];
    int i = 0;
    for (; s[idx + i] == c; ++i)
      ;
    if (idx + i >= sz) {
      ans += i / 3 * 2 + (i % 3 == 0 ? 0 : 1);
      break;
    }
    c = s[idx + i];
    int j = 0;
    for (; s[idx + i + j] == c; ++j)
      ;
    int i_div = i / 3;
    int i_rem = i % 3;
    int j_div = j / 3;
    int j_rem = j % 3;
    if (i_rem == 2 && j_rem == 2) {
      ans += (i_div + j_div) * 2 + 3;
      idx += i + j;
    } else {
      ans += i_div * 2 + (i_rem == 0 ? 0 : 1);
      idx += i;
    }
  }
end_loop:
  cout << ans << endl;
  return 0;
}
