#include <bits/stdc++.h>
using namespace std;
vector<int> nums;
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0);
  string s;
  cin >> s;
  int c = 1;
  for (int i = 1; s[i]; i++) {
    if (s[i] == s[i - 1])
      c++;
    else {
      nums.push_back(c);
      c = 1;
    }
  }
  nums.push_back(c);
  int i = 0;
  int ans = 0;
  while (i < nums.size()) {
    if (nums[i] % 3 == 0) {
      ans += (nums[i] / 3) * 2;
      i++;
    } else if (nums[i] % 3 == 1) {
      ans += (nums[i] / 3) * 2;
      ans++;
      i++;
    } else {
      if (i == nums.size() - 1) {
        ans += (nums[i] / 3) * 2;
        ans++;
        i++;
      } else if (nums[i + 1] % 3 == 2) {
        ans += (nums[i] / 3) * 2;
        ans += 2;
        nums[i + 1]--;
        i++;
      } else {
        ans += (nums[i] / 3) * 2;
        ans++;
        i++;
      }
    }
  }
  cout << ans;
  return 0;
}
