import sys

stdin = sys.stdin



ni = lambda: int(ns)

ns = lambda: stdin.readline().rstrip()

na = lambda: map(int, stdin.readline().split())



from itertools import groupby



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

      flag = False

    if n == 0:

      print(group, file=sys.stderr)

      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

    print(group, c, d, file=sys.stderr)

    ans += c + d

  if flag:

    ans -= 1

  print(ans, file=sys.stderr)

  return ans



def solve():

  s = ns()

  print(max(f(s), f(s[::-1])))





if __name__ == '__main__':

  solve()

import sys

from itertools import groupby



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

      flag = False

    if n == 0:

      print(group, file=sys.stderr)

      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

    print(group, c, d, file=sys.stderr)

    ans += c + d

  if flag:

    ans -= 1

  print(ans, file=sys.stderr)

  return ans



def solve():

  s = input()

  print(f(s))





if __name__ == '__main__':

  solve()

import sys

stdin = sys.stdin
ni = lambda: int(ns)
ns = lambda: stdin.readline().rstrip()
na = lambda: map(int, stdin.readline().split())
from itertools import groupby


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
            flag = False
        if n == 0:
            print(group, file=sys.stderr)
            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
        print(group, c, d, file=sys.stderr)
        ans += c + d
    if flag:
        ans -= 1
    print(ans, file=sys.stderr)
    return ans


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


if __name__ == "__main__":
    solve()

import sys
from itertools import groupby


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
            flag = False
        if n == 0:
            print(group, file=sys.stderr)
            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
        print(group, c, d, file=sys.stderr)
        ans += c + d
    if flag:
        ans -= 1
    print(ans, file=sys.stderr)
    return ans


def solve():
    s = input()
    print(f(s))


if __name__ == "__main__":
    solve()

- -stdin = sys.stdin -ni = lambda: int(ns) -ns = lambda: stdin.readline().rstrip() -na = lambda: map(int, stdin.readline().split()) -    s = ns() -    print(max(f(s), f(s[::-1]))) +    s = input() +    print(f(s))