#include <bits/stdc++.h>
using namespace std;
template <typename T1, typename T2>
inline void chkmin(T1 &x, T2 y) {
  x = (x > y ? y : x);
}
template <typename T1, typename T2>
inline void chkmax(T1 &x, T2 y) {
  x = (x < y ? y : x);
}
using ll = long long;
const string FILENAME = "input";
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  string s;
  cin >> s;
  vector<pair<char, int> > st;
  for (auto x : s) {
    if (st.empty() || st.back().first != x) {
      st.emplace_back(x, 1);
    } else {
      st.back().second++;
    }
  }
  int res = 0;
  int f = 0;
  for (auto x : st) {
    res += (x.second / 3) * 2 + (x.second % 3 != 0);
    if ((f % 3 == 2 || (f % 3 == 1 && f >= 4)) &&
        (x.second % 3 == 2 || (x.second % 3 == 1 && x.second >= 4))) {
      res++;
      x.second--;
    }
    f = x.second;
  }
  cout << res << endl;
  return 0;
}
