from collections import defaultdict, deque, Counter
import sys
import heapq
import math

# input = sys.stdin.readline

sys.setrecursionlimit(1000000000)

MIN = -10 ** 9
MOD = 10 ** 9 + 7


def f(n):
    a = n // 3
    b = n % 3
    if b == 0:
        return a * 2, False
    if b == 1:
        return a * 2 + 1, False

    return a * 2 + 1, True


def solve(s):
    last = ""
    c = 1
    res = 0
    last_flag = False
    for i in range(0, len(s)):
        if last == s[i]:
            c += 1
            continue

        k, k_flag = f(c)
        if last_flag and k_flag:
            res += k + 1
            last_flag = False
        else:

            res += k
            last_flag = k_flag
        c = 1
        last = s[i]
    return res


def main():
    s = input()
    # N = int(input())
    print(solve(s))
    # N, A, B = [int(a) for a in input().split()]
    # A = [
    #     [int(a) for a in input().split()]
    #     for _ in range(N)
    # ]


if __name__ == '__main__':
    main()
