Longest Alternating SubstringMedium

Longest Alternating Substring

MediumPractice library · +20 XPstringssliding window

Given a string S, find the length of the longest substring that consists of alternating characters. An alternating character substring is one where no two adjacent characters are the same.

Input

The first line contains a string S.

Output

Print a single integer representing the length of the longest alternating substring.

Constraints

1 <= |S| <= 200000, S consists of lowercase English letters.

Time limit 1 s (native code; slower languages get more)Memory 256 MB16 hidden tests

Example 1

Input
abacaba
Output
7

The longest alternating substring is 'abacaba' itself, length 7.

Example 2

Input
aaaaa
Output
1

The longest alternating substrings are 'a', 'a', 'a', 'a', 'a', each of length 1.

Hints