#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1000000000
#define mod 1000000007
typedef long long ll;
const ll 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;
    //2文字以上のブロックはいらない
    ll ans=0,i=0;
    vector<ll> v;
    while(i<s.size()){
        char tmp=s[i];
        ll c=0;
        while(tmp==s[i]&&i<s.size()){
            i++;
            c++;
        }
        v.push_back(c);
    }
    bool f[v.size()]={};
    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]--;
            f[i]=true;
        }
        else if(v[i-1]%3!=0&&(!f[i-1])){
            v[i-1]--;ans++;
        }
        else if(i!=v.size()-1&&v[i+1]%3!=0){
            v[i+1]--;ans++;
            f[i]=true;
        }
    }
    
    rep(i,v.size()){
        ans+=(v[i]/3)*2;
        if(v[i]%3!=0) ans++;
    }
    cout<<ans<<endl;
    return 0;
}
