#K9691. Run-Length Encoding Compression

    ID: 39086 Type: Default 1000ms 256MiB

Run-Length Encoding Compression

Run-Length Encoding Compression

You are given a string s. Your task is to compress the string using a simple run-length encoding algorithm:

  • If a character appears consecutively more than once, replace the consecutive block with the character followed by the count of its repetitions.
  • If a character appears only once, it remains unchanged.

After compressing the string, compare its length with the original string. If the compressed string is strictly shorter than the original string, output the compressed string; otherwise, output the original string.

For example:

  • aaabbccccc is compressed to a3b2c5.
  • abcd remains abcd because the compressed version would not reduce the length.

Ensure that your solution reads input from stdin and writes output to stdout.

inputFormat

The input consists of a single line containing a non-empty string s. The string may be empty as well. Read the string from stdin.

outputFormat

Output the compressed string (or the original string if the compressed version is not shorter) to stdout.

## sample
aaabbccccc
a3b2c5