Under construction

Still being built. Things may change

Not So Distant Strings

Time limit1sMemory limit1024 MB

Summary
Given a digit string s and k, output the k-th length-n digit string when all strings are sorted by digit distance to s, then lexicographically.
Level

Hard8 of 10

Topics
Dynamic programming, Combinatorics, Greedy, Binary search
Solved
No attempts yet

Problem

Today in the string theory lecture, Professor Morris taught the students several ways to measure the distance between two strings. One of them works as follows. Let ss and tt be two strings of length nn made only of decimal digits. Professor Morris calls the digit distance between them the sum of absolute differences of the digits at equal positions, that is ∑i=1n∣si−ti∣\sum_{i=1}^{n} |s_i - t_i|, where sis_i is the digit at position ii in ss and tit_i is the digit at position ii in tt.

For homework, the professor gave each student a string of length nn and asked them to write out all strings of length nn (there are 10n10^n of them) in non-decreasing order of digit distance to that string. When two strings have the same distance, they are compared lexicographically.

The professor has little time to check each student's work, so he also gave each student a number kk and asks only for the string in the kk-th place of the list. The students do not want to do this long and tedious task by hand, so they asked you to write a program that outputs the answer for a given string and number kk.

Input

The first line contains two integers nn and kk (1≤n≤200 0001 \leq n \leq 200\,000, 1≤k≤min⁡(10n,1018)1 \leq k \leq \min(10^{n}, 10^{18})), the length of the string given by the professor and the position kk in the final sequence that the professor is interested in.

The second line contains the string of nn decimal digits.

Output

Print the string of nn decimal digits that is written in the kk-th place of the sequence.

Hint

In the second example, the first seven words of the list are 00000, 00001, 00010, 00100, 01000, 10000, and 00002.

A word x1,x2,…,xax_1, x_2, \ldots, x_a is not greater than a word y1,y2,…,yby_1, y_2, \ldots, y_b in lexicographic order if one of the following two conditions holds:

  • a≤ba \leq b and x1=y1,…,xa=yax_1 = y_1, \ldots, x_a = y_a, so the first word is a prefix of the second.
  • There is a position 1≤j≤min⁡(a,b)1 \leq j \leq \min(a, b) such that x1=y1,…,xj−1=yj−1x_1 = y_1, \ldots, x_{j-1} = y_{j-1} and xj<yjx_j < y_j. In other words, at the first position where the words differ, the letter in the first word is smaller.

Examples3

  1. Example 1

    Input
    5 1
    00000
    
    Expected output
    00000
    
  2. Example 2

    Input
    5 7
    00000
    
    Expected output
    00002
    
  3. Example 3

    Input
    3 44
    132
    
    Expected output
    212