Problem:
Swapping Characters

You are given a string and a number k. You are suggested to generate new strings by swapping any adjacent pair of characters in the string up to k times. Write a program to report the lexicographically smallest string among them.

Input

The input is given in the following format.

s
k

The first line provides a string s. The second line provides the maximum number of swapping operations k (0 ≤ k ≤ 109). The string consists solely of lower-case alphabetical letters and has a length between 1 and 2 × 105.

Output

Output the lexicographically smallest string.

Sample Input 1

pckoshien
3

Sample Output 1

ckopshien

Sample Input 2

pckoshien
10

Sample Output 2

cekophsin

Solution in Ruby (judge verdict: Memory Limit Exceeded)

a = gets.chomp.split("")
n = gets.to_i
def f(a, n)
    return a if n == 0
    return a if a == []
    c = a[0]
    m = a[0..[a.size-1, n].min].min
    i = a.index(m)
    b = (i == 0 ? [] : a[0..i-1]) + a[i+1..-1]
    return [m] + f(b, n - i)
end
puts f(a, n).join