#include <bits/stdc++.h>
using namespace std;
int main() {
  cout << fixed << setprecision(6);
  string s;
  cin >> s;
  char prev_c = 'A';
  vector<pair<char, int>> charLen;
  for (int i = 0; i < s.length(); ++i) {
    if (s[i] != prev_c) charLen.push_back(make_pair(s[i], 0));
    ++(charLen.back().second);
    prev_c = s[i];
  }
  int cnt = s.length();
  for (int i = 0; i < charLen.size() - 1; ++i) {
    if ((charLen[i].second - 1) % 3 > 0 &&
        (charLen[i + 1].second - 1) % 3 > 0) {
      --charLen[i].second;
      --charLen[i + 1].second;
      --cnt;
    }
  }
  for (auto it : charLen) cnt -= ((it.second - 1 + 2) / 3);
  cout << cnt << endl;
  return 0;
}
