S = input()

count = [[S[0], 1]]
count_idx = 0
for i in range(len(S)-1):
  if S[i] == S[i+1]:
    count[count_idx][1] += 1
  else:
    count.append([S[i+1], 1])
    count_idx += 1

count_num = 0
x = 0
while x < len(count):
  if x < len(count) - 1 and count[x+1][1] % 3 == 2 and count[x+1][1] >= 5:
    count_num += 1
    count[x][1] -= 1
    count[x+1][1] -= 1
  if count[x][1] % 3 == 2 and count[x][1] >= 5 and x == len(count) - 1:
    count_num += (count[x][1] - 5) * 2 + 2
    x += 1
  elif count[x][1] % 3 == 2 and count[x][1] >= 5:
    count_num += ((count[x][1] - 1) // 3) * 2 + (count[x][1] - 1) % 3 + 1
    x += 1
    count[x][1] -= 1
  elif count[x][1] % 3 == 0 or count[x][1] % 3 == 1:
    count_num += (count[x][1] // 3) * 2 + count[x][1] % 3
    x += 1
  else:
    if x < len(count) - 1:
      count_num += 2
      x += 1
      count[x][1] -= 1
    else:
      count_num += 1
      break
print(count_num)