#include <bits/stdc++.h>
using namespace std;
int main(int argc, char const *argv[]) {
  string S;
  std::cin >> S;
  std::vector<pair<char, int>> ans;
  char now = 'A';
  for (int i = 0; i < S.size(); i++) {
    if (now != S[i]) {
      ans.push_back(make_pair(S[i], 1));
      now = S[i];
    } else
      ans[ans.size() - 1].second++;
  }
  int count = 0;
  for (int i = 0; i < ans.size() - 1; i++) {
    if (ans[i].second >= 2 && ans[i - 1].second >= 2 &&
        ans[i].second % 3 != 1) {
      ans[i].second--, ans[i + 1].second--;
      count++;
    }
  }
  for (int i = 0; i < ans.size(); i++) {
    if (ans[i].second >= 1) {
      if (ans[i].second % 3 == 0)
        count += 2 * (ans[i].second / 3);
      else if (ans[i].second % 3 == 1)
        count += 2 * (ans[i].second / 3) + 1;
      else
        count += 2 * (ans[i].second / 3) + 1;
    }
  }
  std::cout << count << '\n';
  return 0;
}
