#C13508. Run-Length Encoding Compression
Run-Length Encoding Compression
Run-Length Encoding Compression
Given a string, compress it using the Run-Length Encoding (RLE) algorithm. In RLE, consecutive repeated characters are replaced by a single character followed by the number of repetitions. However, if the compressed string is not strictly shorter than the original, you must output the original string.
Mathematically, if we denote the length of the compressed string as \(L_e\) and the original string length as \(L_o\), then the output is defined as:
\(\text{output} = \begin{cases}\text{compressed}\quad & \text{if } L_e < L_o,\\ \text{original}\quad & \text{otherwise.}\end{cases}\)
For example, given the input aaabbcccc
, the output would be a3b2c4
.
inputFormat
The input consists of a single line containing the string to compress.
outputFormat
Output a single line: the compressed string if its length is strictly less than the original string's length, otherwise the original string.
## sampleaaabbcccc
a3b2c4