#C12718. Look-and-Say Sequence Generation

    ID: 42176 Type: Default 1000ms 256MiB

Look-and-Say Sequence Generation

Look-and-Say Sequence Generation

The look-and-say sequence is a sequence of numbers generated by describing the previous term. Given a starting string s and an integer n, your task is to compute the n-th term in the look-and-say sequence.

How to generate the next term:

  • Read off the digits of the current term, counting the number of consecutive identical digits.
  • Write down the count followed by the digit itself.

For example, if s = "1":
Term 1: 1
Term 2: 11 (one 1)
Term 3: 21 (two 1s become 21)
Term 4: 1211 (one 2 then one 1)

Note: All formulas in this problem are represented in LaTeX format if needed. For instance, the recurrence can be represented as: \(a_{n+1} = \text{next}(a_n)\).

inputFormat

The input consists of a single line containing a starting string s and an integer n separated by whitespace. The string s is composed of digits, and n is a positive integer.

outputFormat

Output the n-th term of the look-and-say sequence on a single line.

## sample
1 1
1