#C11443. String Compression

    ID: 40760 Type: Default 1000ms 256MiB

String Compression

String Compression

You are given a string s consisting of alphabetical characters. Your task is to compress the string by replacing consecutive repeated characters with the character followed by the count of repetitions. If the resulting compressed string is not strictly shorter than the original string, output the original string.

For example, given the string "aaabbcc", the compressed version is "a3b2c2" which is shorter than the original, so the answer is "a3b2c2". However, if the input is "abcd", there is no compression benefit and so you output "abcd".

The compression rule is applied case-sensitively (i.e., 'a' and 'A' are treated as different characters).

Note: Use LaTeX for any formulas if needed. For instance, if you wish to denote the length of a string s as \( |s| \), and the compressed string as \( c \), the condition to output the compressed string is \( |c| < |s| \).

inputFormat

The input consists of a single line containing a non-empty string s which you need to compress.

Input Format:

The first and only line of input contains the string s

outputFormat

Output a single line: the compressed string if the compressed version is strictly shorter than the original string; otherwise, output the original string.

Output Format:

A single line with the resulting string
## sample
aaabbcc
a3b2c2