cswork / OAOpen practice workspace

Akuna CapitalOA #17

K Smallest Substring

Estimated MediumJudge-ready

Topics (AI-labelled)Two PointersStrings

In a string consisting only of 0/1, choose a substring that contains exactly k ones; first minimize the length, and among equal lengths take the lexicographically smallest. The statement guarantees that an answer exists.

Input

The first line contains the binary string s; the second line contains the integer k. This site follows the original length range 1≤k≤|s|≤1000, and explicitly adds the statement's guarantee that 1≤k≤(the total number of 1s in s).

Output

Output the valid substring that is smallest by (length, lexicographic order).

Example 1

Input:

0101101
3

Output:

1011

Example 2

Input:

111
1

Output:

1

Example 3

Input:

0010100
1

Output:

1

Editorial

Loading solution…