String Compression (Run-Length Encoding)

Compress string in-place using counts of repeated characters. For example, "aabcccccaaa" becomes "a2b1c5a3".

Input Format

One line string s.

Output Format

Compressed string (if shorter than original).

Constraints

  • 1 <= len(s) <= 1000.

Examples

Example 1:

Input:

s = "aabcccccaaa"

Output:

a2b1c5a3

Explanation:

Consecutive counts of each letter.

Loading...
String Compression (Run-Length Encoding)