#!/usr/bin/env python

import sys

def search(s):
    prev=""
    n=1
    j=-1
    for i,c in enumerate(s):
        if prev==c:
            if j<0: j=i-1
            n+=1
        else:
            if n>1: break
        prev=c
    #
    return j,n

s= sys.stdin.readline().strip()
n= len(s)

i= 0
c= 0
while i<n:    
    j,m= search(s[i:])
    if j<0:
        c+= n-i
        break
    #
    mod= m%3
    if mod==0: c+= ( m//3 ) * 2
    elif mod==1: c+= ( (m-1)//3  ) * 2 + 1
    else: c+= ( (m+1)//3 ) * 2
    c+= j
    i+= (j+m)
    if i==n:
        if mod==2: c-=1
    else:
        i+=1
print( c )
