#include <bits/stdc++.h>
using namespace std;
int main() {
  string x;
  cin >> x;
  char cur = x[0];
  int cnt = 0;
  int k = 0;
  for (int i = 0; i < x.length(); i++) {
    if (cur != x[i]) {
      k += (cnt + 2) / 3;
      cnt = 1;
      cur = x[i];
    } else {
      cnt++;
    }
  }
  k += (cnt + 2) / 3;
  int k2 = 0;
  cnt = 0;
  reverse(x.begin(), x.end());
  cur = x[0];
  for (int i = 0; i < x.length(); i++) {
    if (cur != x[i]) {
      k2 += (cnt + 2) / 3;
      cnt = 1;
      cur = x[i];
    } else {
      cnt++;
    }
  }
  k2 += (cnt + 2) / 3;
  cout << max(k + 1, k2 + 1) << '\n';
}
