#K58132. String Compression
String Compression
String Compression
Given a string s, your task is to compress it by replacing sequences of repeated characters with the character followed by the number of repetitions. Specifically, for a sequence of a character c that appears consecutively n times, the compressed format will be cn
(i.e. c
concatenated with n
). Formally, if the input string is
$$ s = c_1c_1\cdots c_1\; c_2c_2\cdots c_2 \; \cdots \; c_kc_k\cdots c_k, $$
then the compressed string is
$$ compressed(s) = c_1\;n_1\; c_2\;n_2 \; \cdots \; c_k\;n_k. $$
However, if the compressed string is not strictly shorter than the original string, you must output the original string.
inputFormat
The input consists of a single line containing the string to be compressed, provided via standard input (stdin).
outputFormat
Output the compressed string to standard output (stdout). If the compressed string is not shorter than the original string, output the original string.## sample
aabcccccaaa
a2b1c5a3