#K61572. String Compression
String Compression
String Compression
You are given a string s
. Compress the string by replacing each contiguous block of the same character with a single instance of that character followed by the count of its consecutive appearances. Formally, for a string \( s \) of length \( n \), for every maximal substring where all characters are equal, replace it with the character and the number \( (j-i+1) \) where the substring extends from index \( i \) to \( j \). If the compressed string is not strictly shorter than the original string, output the original string.
Example: For \( s = \texttt{'aaabbbcccaaa'} \), the compressed string is \( \texttt{'a3b3c3a3'} \) which is shorter than \( s \).
inputFormat
The input is provided via stdin as a single line containing a non-empty string \( s \) consisting of uppercase and lowercase English letters.
outputFormat
Print the compressed string to stdout if its length is strictly less than the original string's length; otherwise, print the original string.
## sampleaaabbbcccaaa
a3b3c3a3