#P3519. Maximize Letter Frequency Difference

    ID: 16773 Type: Default 1000ms 256MiB

Maximize Letter Frequency Difference

Maximize Letter Frequency Difference

A word consisting of \( n \) lower-case letters of the English alphabet (a–z) is given. We want to choose a non-empty contiguous fragment of the word in order to maximize the difference between the number of occurrences of the most frequent letter and the least frequent letter in the fragment.

Note that the least frequent letter in the chosen fragment must occur at least once. In particular, if the fragment contains occurrences of only one letter, then the most and the least frequent letters are the same, resulting in a difference of 0.

Your task is to determine the maximum possible difference.

inputFormat

A single line containing a word of ( n ) lower-case English letters (from 'a' to 'z').

outputFormat

Output a single integer representing the maximum possible difference between the frequencies of the most frequent letter and the least frequent letter (with the least frequent letter appearing at least once) in any contiguous fragment of the word.

sample

a
0