#C11642. Run-Length Encoding Compression
Run-Length Encoding Compression
Run-Length Encoding Compression
You are given a string s
. Your task is to compress the string using Run-Length Encoding (RLE). For each group of consecutive identical characters in s
, you should replace the group with the character followed by the number of times it appears consecutively. Formally, if a character c
appears consecutively k
times, you would write ck
in the compressed string. However, if the length of the resulting compressed string is not strictly less than the length of the original string, then you should output the original string instead.
In mathematical terms, if we denote by len(s
) the length of the original string, and by len(s'
) the length of its compressed version constructed as described, then you must output s'
if
$$
len(s') < len(s),
$$
otherwise, output s
.
The input string consists of only visible ASCII characters and can be empty.
inputFormat
The input consists of a single line containing the string s
.
outputFormat
Output a single line containing the compressed version of the string if its length is strictly less than that of the original string; otherwise, print the original string.
## sampleaabcccccaaa
a2b1c5a3