#C4208. Longest Equal Substring

    ID: 47721 Type: Default 1000ms 256MiB

Longest Equal Substring

Longest Equal Substring

You are given a string s consisting only of characters 'a', 'b', and 'c'. Your task is to find the length of the longest contiguous substring in which the number of 'a's, 'b's, and 'c's are equal.

Example:

Input: abacbc
Output: 6

Since in the entire string the counts of 'a', 'b', and 'c' are all 2.

</p>

Implement an efficient solution that reads the input from stdin and prints the output to stdout.

inputFormat

A single line containing the string s. The string consists only of the characters 'a', 'b', and 'c'.

outputFormat

Print a single integer representing the length of the longest substring in which the counts of 'a', 'b', and 'c' are equal. If no such substring exists, output 0.## sample

abacbc
6