#C14816. String Compression

    ID: 44507 Type: Default 1000ms 256MiB

String Compression

String Compression

You are given a string (s). Your task is to compress it by replacing each group of consecutive repeated characters with the character followed by the count of repetitions. For example, the substring 'aaa' should be compressed as 'a3'. Formally, if a substring consists of a character (c) repeated (n) times consecutively, its compressed form is (c n) (displayed without any spaces, e.g. 'a3'). However, if the compressed string is not strictly shorter than the original string, then you must output the original string. For instance, if the length of the compressed string ((L_c)) is not less than the length of the original string ((L_o)), that is, if (L_c \ge L_o), then output (s) instead of the compressed form.

inputFormat

The input consists of a single line containing the string (s). The string may be empty and consists of ASCII characters.

outputFormat

Output a single line containing the compressed string according to the rules described. If the compressed string is not strictly shorter than the original string, output the original string.## sample

aabcccccaaa
a2b1c5a3