#C2479. String Compression
String Compression
String Compression
You are given a string s. Your task is to compress the string using Run-Length Encoding (RLE). For each maximal group of consecutive identical characters in the string, replace the group by the character followed by the number of occurrences. Formally, for a string \( s = s_1 s_2 \dots s_n \), if it can be divided into groups such that
\( s = c_1^{k_1} c_2^{k_2} \dots c_m^{k_m} \),
then the compressed string is defined as
\( r(s) = c_1 k_1 c_2 k_2 \dots c_m k_m \).
Return the compressed string if and only if its length is strictly less than the original string's length. Otherwise, return the original string.
inputFormat
The input consists of a single line containing the string s. The string may be empty and will consist of printable ASCII characters.
outputFormat
Output a single line: the compressed string if the compressed version is shorter than the original string, or the original string otherwise.
## sampleaabcccccaaa
a2b1c5a3