#include <bits/stdc++.h>
using namespace std;
const long long LINF = 1001002003004005006ll;
int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int main() {
  string s;
  cin >> s;
  long long ans = 0, i = 0;
  vector<long long> v;
  while (i < s.size()) {
    char tmp = s[i];
    long long c = 0;
    while (tmp == s[i] && i < s.size()) {
      i++;
      c++;
    }
    v.push_back(c);
  }
  for (int i = 0; i < v.size(); i++) {
    if (v.size() == 1) continue;
    if (v[i] % 3 != 2) continue;
    if (i == 0) {
      ans++;
      v[i + 1]--;
    } else if (v[i - 1] % 3 != 0) {
      v[i - 1]--;
      ans++;
    } else if (i != v.size() - 1 && v[i + 1] % 3 != 0) {
      v[i + 1]--;
      ans++;
    }
  }
  for (int i = 0; i < v.size(); i++) {
    ans += (v[i] / 3) * 2;
    if (v[i] % 3 != 0) ans++;
  }
  cout << ans << endl;
  return 0;
}
