#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e10;
const long long ZERO = 0;
signed main() {
  string S;
  cin >> S;
  S.insert(0, "0");
  vector<long long> vec;
  long long N = 1;
  for (long long i = S.size() - 1; i >= 1; i--) {
    if (S.at(i) == S.at(i - 1)) {
      N++;
    } else {
      vec.push_back(N);
      N = 1;
    }
  }
  long long answer = 0;
  vector<long long> cnt(vec.size());
  for (long long i = 0; i < vec.size(); i++) {
    cnt.at(i) = vec.at(i) % 3;
  }
  for (long long i = 0; i < vec.size(); i++) {
    answer += vec.at(i) / 3 * 2;
  }
  cnt.push_back(1);
  long long A = 0;
  for (long long i = 0; i < cnt.size(); i++) {
    if (cnt.at(i) == 1) {
      answer++;
      if (A == 1) {
        answer++;
      } else if (A > 1) {
        answer += A + 1;
      }
      A = 0;
    }
    if (cnt.at(i) == 2) {
      A++;
    }
    if (cnt.at(i) == 0) {
      if (A == 1) {
        answer++;
      } else if (A > 1) {
        answer += A + 1;
      }
      A = 0;
    }
  }
  cout << answer - 1 << endl;
}
