#C13359. Run-Length String Compression
Run-Length String Compression
Run-Length String Compression
Given a non-empty string s consisting of lowercase letters, compress the string using run-length encoding. In this method, each group of consecutive identical characters is replaced by the character followed by the number of occurrences. If the compressed string is not strictly shorter than the original string, then return the original string.
Mathematically, let \( n \) be the length of the original string and \( m \) be the length of the compressed string. If \( m \geq n \), then output the original string; otherwise, output the compressed string.
Example: For the input aaabbcccaaa
, the compressed string is a3b2c3a3
.
inputFormat
The input is provided via stdin and consists of a single line containing the string s. The string is composed only of lowercase letters (a–z) and its length does not exceed 100 characters.
outputFormat
The output should be printed to stdout as a single line. It contains the compressed string if the compressed version is shorter than the original string; otherwise, it outputs the original string.
## sampleaaabbcccaaa
a3b2c3a3