#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using vi = vector<int>;

int func(int x){
	if( x%3 == 2) return x/3+1;
	return x/3;
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	string s;
	cin >> s;
	int n = s.size();
	vi v;
	int cnt = 1;
	for(int i = 1;i<n;i++){
		if(s[i] != s[i-1]){
			v.push_back(cnt);
			cnt = 1;
		}
		else cnt++;
	}
	v.push_back(cnt);
	int b = v.size();
	for(int i = 0;i<b;i++){
		res+= func(v[i]);
	}
	cnt = 0;
	for(int i = 0;i<b;i++){
		if( v[i] == 1){
			res -= cnt/2;
			cnt = 0;
		}
		if( v[i]%3 == 2){
			cnt++;
		}
	}
	res -= cnt/2;
	cout << n - res << endl;
}

