A factory conveyor belt carries a line of colored tokens, one uppercase letter per token representing its paint color. The packing station groups every maximal run of consecutive identical tokens into crates, where each crate can hold at most nine tokens. For a run of length L, the station fills crates greedily from the front — full crates of nine tokens until fewer than nine remain, then one final crate with whatever remains (if any) — and for each crate, in the order it was filled, writes its token count followed immediately by the color letter, with no separators between entries. Given the belt's token sequence, produce the full packing code.
A single line containing the string s of the belt's tokens.
Print a single line containing the packing code: the concatenation, in order, of (crate size as a single digit 1-9) followed by (the crate's color letter), for every crate across every run.
1 <= length of s <= 200000s consists only of uppercase English letters A-Z.Example 1
Input
AAAAAAAAAAA
Expected
9A2A
Explanation
All 11 tokens are the color A. The station fills one crate of 9 A's, then a final crate with the remaining 2 A's, giving '9A2A'.
Example 2
Input
AAABBBBBBBBBBCC
Expected
3A9B1B2C
Explanation
Three separate runs: the 3 A's fit in one crate ('3A'); the run of 10 B's fills a crate of 9 then a crate of 1 ('9B1B'); the 2 C's fit in one crate ('2C'). Concatenating gives '3A9B1B2C'.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →