Look-and-Say String

Interview

Time limit1sMemory limit128 MB

Summary
Apply the look-and-say run-length encoding to a digit string n times and print the resulting string.
Level

Easy3 of 10

Topics
String, Implementation, Simulation, Two pointers
Solved
No attempts yet

Problem

You are given a string composed only of the digits 0 through 9. Consider the following operation that turns it into a new string.

Read the string from the left, one character at a time. Whenever the same digit aa appears rr times in a row, write the count rr immediately followed by the digit aa, with no space between them. Reading all the way to the right end and finishing the last write together count as a single operation, no matter how many individual writes happened along the way. Each operation from the second onward is applied the same way, using the string produced by the previous operation as its new input.

For example, given "122244", reading from the left there is one 1, three 2s, and two 4s, so one operation yields "113224". For "44444444444" (eleven 4s), one operation yields "114".

Write a program that, for a given string of length at most 100, outputs the string obtained after performing the operation nn times, where n≤20n \le 20.

Input

Two lines. The first line contains the number of operations nn. The second line contains the initial string.

Output

Output, on a single line, the string obtained after performing the operation the specified number of times, followed by a newline.

Examples3

  1. Example 1

    Input
    5
    11
    
    Expected output
    13112221
    
  2. Example 2

    Input
    1
    122244
    
    Expected output
    113224
    
  3. Example 3

    Input
    1
    44444444444
    
    Expected output
    114