In his latest 15-122 (Principles of Imperative Computation) homework, Edward learned how to compress strings using prefix-free codes generated by Huffman coding. Although this is a great start, he wonders whether better compression algorithms exist by abusing repetitions in the string. For example, if we define the repeatability of a string
However, using repeatability as a measure of compressibility is not quite perfect: the string aaabaab
only has repeatability aaabaab
is huffman
is
In order for this metric to be useful though, it remains to find an efficient algorithm that computes the compressibility of any given string
Constraints
Subtask 1 [10%]
Subtask 2 [20%]
Subtask 3 [70%]
No additional constraints.
Input Specification
The first and only line contains a string
Output Specification
Output the compressibility of
Sample Input
aaabaab
Sample Output
34
Explanation for Sample
There are
There are
There is
Thus, the compressibility can be computed as
Comments