#include <bits/stdc++.h>
using namespace std;
const int T = 2e5 + 5;
int N = 0;
int len[T], F[T][2][2];
int cal(int x) { return x / 3 * 2 + (x % 3 > 0); }
int main() {
  string S;
  cin >> S;
  int cnt = 1;
  for (int i = 1; i < S.size(); i++) {
    cnt += (S[i] == S[i - 1]);
    if (S[i] != S[i - 1] or i == S.size() - 1) {
      len[++N] = cnt;
      cnt = 1;
      if (i == S.size() - 1 and S[i] != S[i - 1]) len[++N] = 1;
    }
  }
  for (int i = 1; i <= N; i++) len[0] = 0;
  F[1][1][0] = F[1][1][1] = int(-1e9);
  for (int next = 0; next < 2; next++) F[1][0][next] = cal(len[1] - next);
  int ans = 0;
  for (int i = 2; i <= N; i++)
    for (int a = 0; a < 2; a++)
      for (int b = 0; b < 2; b++) {
        if (len[i] < a + b) continue;
        if (i == N and b == 1) continue;
        int mx = 0;
        for (int a_ = 0; a_ < 2; a_++)
          for (int b_ = 0; b_ < 2; b_++) {
            if (b_ != a) continue;
            mx = max(mx, F[i - 1][a_][b_] + a + cal(len[i] - a - b));
          }
        F[i][a][b] = mx;
        ans = max(ans, mx);
      }
  cout << ans;
}
