#include <bits/stdc++.h>
using namespace std;
int n, ans, k;
const int N = 300010;
char a[N], t[N];
int main() {
  scanf("%s", a + 1);
  int len = strlen(a + 1);
  for (int i = 1; i <= len; i++) {
    if (a[i] == a[i - 1]) continue;
    int s = 0;
    for (int j = i; a[j] == a[i]; j++) s++;
    ans += s / 3 * 2;
    if (s % 3) ans++;
    t[++k] = s % 3;
  }
  for (int i = 1; i < k; i++)
    if (t[i] == t[i + 1] && t[i] == 2) ans++, t[i + 1]--;
  cout << ans;
}
