#include <bits/stdc++.h>
using namespace std;
const int maxn = 3e5 + 10;
char s[maxn];
int ans;
vector<int> a;
int main() {
  scanf("%s", s + 1);
  int n = strlen(s + 1);
  for (int i = 1; i <= n; i++) {
    int j = i;
    while (j <= n && s[i] == s[j]) ++j;
    j--;
    a.push_back(j + 1 - i);
    i = j;
  }
  n = (int)a.size();
  for (int i = 0; i < n; i++) {
    if (a[i] == 0) continue;
    if (a[i] == 1) {
      ans++;
      continue;
    }
    if (a[i] == 2) {
      ans += (i != n - 1 ? 2 : 1);
      if (i + 1 < n) a[i + 1]--;
      continue;
    }
    ans += ((a[i] / 3) * 2);
    a[i] %= 3;
    if (a[i] == 1) {
      ans++;
      continue;
    }
    if (a[i] == 2) {
      ans += (i != n ? 2 : 1);
      if (i + 1 < n) a[i + 1]--;
      continue;
    }
  }
  printf("%d\n", ans);
}
