import sys
from itertools import groupby

input = sys.stdin.readline
input_list = lambda: map(int, input().split())

dup = lambda x,y: ((x)+(y)-1)//(y)


def f(x):
  groups = []
  for _, g in groupby(x):
    groups += [list(g)]

  ans = 0
  flag = False
  for group in groups:
    n = len(group)
    if flag:
      n -= 1
    if n == 0:
      continue
    c = (n-1)//3 * 2
    o = n%3
    if o == 0:
      d = 2
    elif o == 1:
      d = 1
    elif o == 2:
      d = 2
      flag = True
    ans += c + d
      
  return ans


def solve():
  s = input()
  print(max(f(s), f(s[::-1])))


solve()