All problems

Problem 54

Run-Length Encoding

Easy · 10 pts · String, Two Pointers

Problem

Run-length encoding compresses a string by replacing each run of identical letters (a maximal block of the same letter in a row) with that letter followed by the length of the run. Every run gets a count, even a run of length 1, and a run can be longer than 9, in which case the count has several digits. For example, "aaabcc" has the runs aaa, b and cc, and is encoded as a3b1c2. Encode the given string.

Input

A single string S of lowercase English letters.

Output

Print the encoded string.

Constraints

1 <= |S| <= 100000

Example input

aaabcc

Example output

a3b1c2

Explanation

"aaabcc" splits into the runs aaa (length 3), b (length 1) and cc (length 2). Writing each letter followed by its run length gives a3b1c2.

Every problem here can be used in a RelayTrixCode team match. Create a room.

Previous: Length of Last Word Next: Valid Palindrome II