s = input()
num = len(s)
ans = 0
pos = 0

while True:
  c = s[pos]
  count = 0
  for i in range(num - pos):
    if s[pos + i] == c:
      count += 1
    else:
      ans += (count//3)*2  
      if i < num:
        if count % 3 == 1:
          ans += 1
        elif count % 3 == 2:
          ans += 2
          pos += 1
      break
  pos += count
  
  if pos >= num:
    ans += (count // 3) * 2 
    if count % 3 != 0:
      ans += 1

    break


print(ans)
