Under construction

Still being built. Things may change

Binary Witch

Time limit1sMemory limit128 MB

Summary
Given a binary string, predict the next L digits by matching suffixes of length 13 down to 1 against earlier occurrences, using the rightmost match.
Level

Medium5 of 10

Topics
String, String matching, Hash map, Implementation
Solved
No attempts yet

Problem

Long ago, in the silent depths of the digital forest, there lived a Binary Witch. She could forecast the weather, telling for any future day whether it would be rainy (00) or sunny (11).

Her magic followed this ancient rule. Let a1,a2,…,aNa_1, a_2, \ldots, a_N be a sequence of binary digits, where ai=0a_i = 0 means day ii was rainy and ai=1a_i = 1 means it was sunny. To predict the weather on day N+1N+1, look at the tt-postfix aN−t+1,aN−t+2,…,aNa_{N-t+1}, a_{N-t+2}, \ldots, a_N made of the last tt elements. If this postfix also occurs somewhere before position N−t+1N-t+1 — that is, if there exists k≤N−tk \le N-t with ak=aN−t+1, ak+1=aN−t+2, …, ak+t−1=aNa_k = a_{N-t+1},\ a_{k+1} = a_{N-t+2},\ \ldots,\ a_{k+t-1} = a_N — then the predicted value is ak+ta_{k+t}.

If the tt-postfix occurs more than once, take the rightmost occurrence, the one with the largest kk. To make a prediction she tries the tt-postfixes in order t=13,12,…,1t = 13, 12, \ldots, 1 and stops as soon as a prediction is produced. If no postfix is found, she predicts rain (00). When more than one day must be forecast, every previously predicted day is assumed correct: if the first predicted value is bb, set aN+1=ba_{N+1} = b, forecast day N+2N+2 from the N+1N+1 values, and so on.

Write a program that performs the witch's task.

Input

The first line contains two integers NN (1≤N≤1061 \le N \le 10^6) and LL (1≤L≤10001 \le L \le 1000), separated by a space. The second line contains a string of NN characters, each 00 or 11.

Output

Print a single string of LL characters: the forecasts for days N+1,N+2,…,N+LN+1, N+2, \ldots, N+L.

Examples3

  1. Example 1

    Input
    10 7
    1101110010
    
    Expected output
    0100100
    
  2. Example 2

    Input
    5 5
    11111
    
    Expected output
    11111
    
  3. Example 3

    Input
    8 8
    01010101
    
    Expected output
    01010101