#K48767. String Compression

    ID: 28494 Type: Default 1000ms 256MiB

String Compression

String Compression

Given a string consisting only of alphabetic characters, your task is to compress it by counting consecutive repeating characters. For each group of the same character, replace it with the character followed by the number of times it appears consecutively. However, if the resulting compressed string is not strictly shorter than the original string, output the original string.

For example, if the input is aabcccccaaa, the compressed string will be a2b1c5a3 because there are 2 a's, 1 b, 5 c's, and 3 a's in order. If the input is abcdef, compressing it would produce a1b1c1d1e1f1 which is longer than the original, so you should return abcdef instead.

Note: The input string may include both uppercase and lowercase letters and can be empty.

The compression procedure can be described by the following formula in LaTeX:

\[ compressed = \begin{cases} \text{For each sequence } (c, count): \, c\, {\rm toString}(count), & \text{if } \sum_{i} (1 + |{\rm toString}(count_i)|) < |s| \ \; s, & \text{otherwise} \end{cases} \]

inputFormat

The input consists of a single line containing the string to be compressed. Read the input from stdin.

outputFormat

Output a single line representing the compressed string if its length is strictly less than the original string; otherwise, output the original string. Write your output to stdout.

## sample
aabcccccaaa
a2b1c5a3