def solve(S):
    if len(S) == 1:
        return 1
    if len(S) == 2:
        if S[0] == S[1]:
            return 1
        return 2
    if len(S) == 3:
        if set(S) == 3:
            return 3
        return 2

    def p_solve(S):
        i = 0
        j = 1
        previous_word = ""
        tans = 0
        splited_words = []
        while j < len(S) and i < len(S):
            if S[i:j] != previous_word:
                splited_words.append(S[i:j])
                previous_word = S[i:j]
                tans += 1
                i = j
                j = i + 1
            else:
                j += 1
        else:
            if S[i:j]:
                tans += 1
                splited_words.append(S[i:j])
        return splited_words

    ans = 0
    for s in [0, 1, 2]:
        if s >= len(S):
            break
        for e in [len(S), len(S) - 1, len(S) - 2]:
            if e <= s:
                continue
            splited_words = p_solve(S[s:e])
            if splited_words[0] != S[:s] and splited_words[-1] != S[e:]:
                if len(splited_words) >= 2:
                    if splited_words[-1] == splited_words[-2] or splited_words[0] == splited_words[1]:
                        continue
                l = len(splited_words)
                if s != 0:
                    l += 1
                if e != len(S):
                    l += 1
                ans = max(ans, l)
    return ans



if __name__ == "__main__":
    S = input()
    print(solve(S))
