#C7849. String Compression

    ID: 51765 Type: Default 1000ms 256MiB

String Compression

String Compression

You are given a non-empty string S consisting of alphabetic characters. Your task is to compress the string by replacing each group of consecutive identical characters with the character followed by the number of occurrences. For example, the string AAABCCDDDD should be compressed to A3B1C2D4 in LaTeX as: \(A3B1C2D4\).

Important: The compression should only be used if the resulting compressed string is strictly shorter than the original. Otherwise, you should output the original string.

Examples:

  • If S = "aabcccccaaa", then the compressed string is a2b1c5a3.
  • If S = "abcdef", the compressed version a1b1c1d1e1f1 is not shorter than abcdef, so the output should be abcdef.
  • If S = "AAABCCDDDD", then the compressed string is A3B1C2D4.

inputFormat

The input consists of a single line containing the string S. The string will only contain uppercase and lowercase English letters.

outputFormat

Output a single line containing the compressed string if its length is strictly less than the original string, otherwise output the original string.

## sample
aabcccccaaa
a2b1c5a3