def main():
    def another(S):
        N = len(S)
        from collections import deque
        cur = deque([S[0]])
        ans1 = 1
        i = 1
        plus = 1
        while i < N:
            if i+plus > N:
                ans1 = -1
                break
            if S[i:i+plus] in cur:
                plus += 1
            else:
                cur.pop()
                cur.append(S[i:i+plus])
                i = i+plus
                plus = 1
                ans1 += 1
        return print(ans1)

    S = input()
    N = len(S)
    if N == 1:
        return print(1)
    elif N == 3:
        if S[0] != S[1] and S[1] != S[2]:
            return print(3)
        return print(2)
    if len(set(S)) == 1:
        return another(S)

    between = [False]*(N-1)
    for i in range(N-1):
        if S[i] == S[i+1]:
            between[i] = True
    for i in range(1, max(1, N-2)):
        if between[i-1] and between[i+1] and not(between[i]):
            between[i-1] = False
            between[i+1] = False
            between[i] = True
        elif between[i-1] and between[i+1] and between[i]:
            between[i-1] = False
            between[i+1] = False
    cnt = 0
    for b in between:
        if b:
            cnt += 1
    print(N-cnt)


if __name__ == '__main__':
    main()
