s = input()
num = len(list(s))
temp = 1
count = 0
base = []

for i in range(1,num):
  if s[i-1] != s[i]:
    count += 2*(temp//3)
    if (temp%3 == 1)or(temp%3 == 2):
      count += 1
    base.append(temp)
    temp = 1
  elif s[i-1] == s[i]:
    temp += 1
    
count += 2*(temp//3)
if (temp%3 == 1)or(temp%3 == 2):
      count += 1
base.append(temp)
temp = 0
for i in range(len(base)):
  if base[i]%3 == 2:
    temp += 1
  else:
    if temp >= 2:
      count += 1
    temp = 0
    
if temp >= 2:
      count += 1
    
print(count)