#include <bits/stdc++.h>
using namespace std;
int n, len[1000010], a[1000010], ans = 0, cnt = 0;
char s[1000010];
inline int read() {
  int ans = 0, k = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') k = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    ans = (ans << 3) + (ans << 1) + (c - '0');
    c = getchar();
  }
  return ans * k;
}
int main() {
  scanf("%s", s);
  n = strlen(s);
  for (register int i = 0; i < n; i++) {
    len[cnt]++;
    if (s[i] != s[i + 1]) {
      a[cnt] = len[cnt] % 3;
      cnt++;
    }
  }
  int f = 0;
  for (register int i = 0; i < cnt; i++) {
    if (a[i] == 2) {
      f ^= 1;
      if (!f) ans += (2 * (len[i - 1] - 1) / 3) + (2 * (len[i] - 1) / 3) + 3;
      continue;
    } else {
      if (f) ans += (2 * (len[i - 1] - 1) / 3) + 1;
      if (a[i] == 0)
        ans += 2 * len[i] / 3;
      else
        ans += (2 * (len[i]) / 3) + 1;
    }
    f = 0;
  }
  if (f) ans += (2 * (len[cnt - 1] - 1) / 3) + 1;
  printf("%d", ans);
  return 0;
}
