#include <bits/stdc++.h>
using namespace std;
int n, ans = 0, lst = 0, len = 0, f = 0;
char s[1000010];
int main() {
  scanf("%s", s);
  n = strlen(s);
  for (register int i = 0; i < n; i++) {
    len++;
    if (s[i] != s[i + 1]) {
      if (len % 3 == 2) {
        f ^= 1;
        if (!f) ans += (2 * (lst - 1) / 3) + (2 * (len - 1) / 3) + 3;
      } else {
        if (f) ans += (2 * (lst - 1) / 3) + 1;
      }
      if (len % 3 == 1) {
        f = 0;
        ans += (2 * len / 3) + 1;
      }
      if (len % 3 == 0) {
        f = 0;
        ans += 2 * len / 3;
      }
      lst = len;
      len = 0;
    }
  }
  if (f) ans += (2 * (lst - 1) / 3) + 1;
  printf("%d", ans);
  return 0;
}
