JOI '05 Final Round P2 - String

View as PDF

Submit solution

Points: 3 (partial)
Time limit: 1.0s
Memory limit: 128M

Problem type

Given a string consisting of decimal digits, 0,1,,9, such as 122244 and 44444444444, consider the following operation which produces from such a string a new string. The operation begins with reading the digits of the given string from left to right. If a digit, say a, appears consecutively r times but not r+1 times for some positive integer r, then produce r¯a without any space between digits, where r¯ is the string of digits representing integer r in decimal notation. Repeat this process on the remainning string (i.e., the substring of the given string beginninig from the r+1-st digit) until the remaining string become empty. By concatenating all the strings produced in this way during the course of processes, without any space between them, a new string of digits is produced. We count the whole course of processes for one application of the operation.

For example, from 122244 a new string 1¯13¯22¯4=113224 is produced by one application of the operation, and from 44444444444 a new string 114. The operation may be applied repeatedly. Your task is to write a program which, given a string of digits of length less than or equal to 100, outputs a new string that is obtained from the string by applying the operation n times, where n20.

Input

The first line contains an integer n, the number of times for the operation to be applied. The second line contains a string to receive the operation.

Output

The output file should contain a single line containing the new string produced by applying the operation n times.

Sample Input

Copy
5
11

Sample Output

Copy
13112221

Comments

There are no comments at the moment.