Problems > Run-Length Encoding

Run-Length Encoding

Difficulty: 1000 2000 ms 128 MB

strings

Compress the string by replacing every maximal run of equal characters with the character followed by the run length. aaabbc becomes a3b2c1.

Input: one line with the string S.

Output: the run-length encoding of S.

Constraints:

  • 1 ≤ |S| ≤ 104
  • S contains lowercase English letters

Sample Tests

Input 1
aaabbc
Output 1
a3b2c1
Input 2
abc
Output 2
a1b1c1

Read the Editorial

Discussion (opens after you solve — no spoilers before)

No comments yet.

Submit Your Solution

Log in or create a free account to run and submit code.