import collections
def func(n):
    return (n+1)//3

S = input()
i = 0
cnt = collections.deque()
while(i<len(S)-1):
    j = 1
    while i<len(S)-1 and S[i] == S[i+1]:
        j += 1
        i += 1
    cnt.append(j)
    i += 1

ans = len(S)
for i in range(len(cnt)-1):
    x = func(cnt[i])+func(cnt[i+1])
    y = func(cnt[i]-1)+func(cnt[i+1]-1)+1
    if x >= y:
        cnt[i+1] -= 1
    ans -= min(x, y)
print(ans)