PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#GD0000208. Pasha tối đa hóa (Pasha Maximizes)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Pasha tối đa hóa (Pasha Maximizes)

Pasha Maximizes

Source: Codeforces

Version: Phuoc Hung OJ Extended

Problem Statement

Pasha has a positive decimal integer aa without leading zeros. He wants to make its value as large as possible.

An operation swaps two adjacent decimal digits. He may perform at most kk operations, not necessarily using the entire allowance. Digits can move across multiple positions only by consecutive adjacent swaps.

Find the largest possible resulting integer.

Input

The only line contains two space-separated values: a positive decimal integer aa and a non-negative integer kk. The representation of aa has no leading zero.

Output

Print the decimal representation of the largest integer obtainable using at most kk adjacent swaps.

Subtasks

  • Subtask 1 (20 points): 1≤a≤1061\le a\le10^6; 0≤k≤1000\le k\le100; aa is positive and has no leading zeros.
  • Subtask 2 (30 points): 1≤a≤10121\le a\le10^{12}; 0≤k≤1000\le k\le100; aa is positive and has no leading zeros.
  • Subtask 3 (50 points): 1≤a≤10181\le a\le10^{18}; 0≤k≤1000\le k\le100; aa is positive and has no leading zeros.

Examples

Input

1034 2

Output

3104

Explanation

Starting from 1034 with k=2k=2, swap the adjacent digits 0 and 3 to obtain 1304, then swap 1 and 3 to obtain 3104. Moving 4 to the first position would require three swaps, which is not allowed. Thus 3 is the best achievable leading digit and 3104 is the maximum.