JOI '05 Final Round P2 - String
View as PDFGiven a string consisting of decimal digits, , such as 
 and 
, 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 
, appears consecutively 
 times but not 
 times for some positive integer 
, then produce
 without any space between digits, where 
 is the string of digits representing integer 
 in
decimal notation. Repeat this process on the remaining string (i.e., the substring of the given
string beginning from the 
-st digit) until the remaining string becomes 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  a new string 
 is produced by one application of
the operation, and from 
 a new string 
.
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
, outputs a new string that is obtained from the string by applying the operation 
 times,
where 
.
Input
The first line contains an integer , 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  times.
Sample Input
5
11
Sample Output
13112221
Comments