#include<bits/stdc++.h>
using namespace std;
#define ls rt<<1
#define rs (rt<<1)+1
#define PI acos(-1)
#define eps 1e-8
#define ll long long
#define fuck(x) cout<<#x<<"     "<<x<<endl;
typedef pair<int,int> pii;
const int inf=2e9;
const int maxn=1e6+10;
int d[4][2]={1,0,-1,0,0,1,0,-1};
//int lowbit(int x){return x&-x;}
//void add(int x,int v){while(x<=n)bit[x]+=v,x+=lowbit(x);}
//int sum(int x){int ans=0;while(x>=1) ans+=bit[x],x-=lowbit(x);return ans;}
inline ll read() {
    ll s = 0,w = 1;
    char ch = getchar();
    while(!isdigit(ch)) {
        if(ch == '-') w = -1;
        ch = getchar();
    }
    while(isdigit(ch))
        s = s * 10 + ch - '0',ch = getchar();
    return s * w;
}
inline void write(ll x) {
    if(x < 0)
        putchar('-'), x = -x;
    if(x > 9)
        write(x / 10);
    putchar(x % 10 + '0');
}

char s[maxn];

int main(){
    int n;
    int ans=0;
    cin>>s+1;
    n=strlen(s+1);
    for(int i=1;i<=n;i++)
    {
        int cnt=0;
        for(int j=i;j<=n+1;j++)
        {
            if(s[i]==s[j])
                cnt++;
            else
            {
                i=j;
                if(cnt%3==0)
                    ans=ans+(cnt/3)*2;
                else
                    ans=ans+(cnt/3)*2+1;
                break;
            }
        }
        if(i>n) break;
        else
            i--;
    }
    cout<<ans<<endl;
    return  0;
}





