import sys

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

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


def f(s):
  b = ''
  n = 0
  l = []
  for c in s:
    if b != c:
      b = c
      l += [n]
      n = 0
    n += 1
  else:
    l += [n]
  if l: l.pop(0)
  
  ans = 0
  for i in range(len(l)):
    n = l[i]
    c = (n//3) * 2
    if n % 3 == 0:
      d = 0
    elif n % 3 == 1:
      d = 1
    elif n % 3 == 2:
      d = 1
      if i+1 < len(l):
        l[i+1] -= 1
        d += 1
    ans += c+d
  
  return ans


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


solve()