#K8901. Efficient String Encoding
Efficient String Encoding
Efficient String Encoding
You are given a string S and your task is to perform a run-length encoding on it. In this encoding, each maximal substring of the same character c is replaced by c
, where count
is the number of occurrences of c in that substring. Formally, if a substring consists of character c repeated n times, it is replaced by c n
written as c\,n
in LaTeX. However, you should only output the encoded string if its length is strictly less than the length of the original string, i.e. if \(|E| < |S|\) where \(E\) is the encoded string and \(S\) is the original string. Otherwise, output the original string.
inputFormat
The input consists of a single line containing a non-empty string S.
outputFormat
Output the run-length encoded string if its length is strictly smaller than the original string; otherwise, output the original string.
## sampleaaabbcccc
a3b2c4