#C12427. String Compression

    ID: 41853 Type: Default 1000ms 256MiB

String Compression

String Compression

Given a string s, implement an algorithm that compresses the string according to the following rules:

  • If the length of s is less than or equal to 2, output s unchanged.
  • Otherwise, replace each sequence of consecutive identical characters with the character followed by the number of occurrences.
  • If the compressed string is not shorter than the original string, output the original string.

For example, for the input aabcccccaaa, the expected compressed output is a2b1c5a3. Mathematical representation of the compression can be described using LaTeX. If a character c appears consecutively k times, then it is represented as \( c k \). The compressed string is the concatenation of all such representations. Let \( L(s) \) be the length of the original string and \( L(c) \) be the length of the compressed string, then the final output is given by:

\[ output = \begin{cases} compressed, & \text{if } L(c)

inputFormat

The input consists of a single line containing the string s to be compressed. The string will only contain standard ASCII characters without spaces.

outputFormat

Output the compressed string according to the rules described. The output is printed to standard output.

## sample
aabcccccaaa
a2b1c5a3