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

#GD0000207. Xóa K chữ số (Remove K Digits)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Xóa K chữ số (Remove K Digits)

Remove K Digits

Source: LeetCode

Version: Phuoc Hung OJ Extended

Problem Statement

A decimal string num represents a non-negative integer. You must remove exactly kk digit positions, keeping the relative order of the remaining digits.

Interpret the remaining string as a decimal integer. Leading zeros have no effect on its value and must be removed from the output. If all digits are deleted or all remaining digits are zero, return 0.

Find the smallest possible integer. This is the standard-input/stdout adaptation of the original LeetCode function task.

Input

  • The first line contains a decimal string num, the initial integer representation.
  • The second line contains an integer kk, the exact number of digit positions to remove.

Let n=∣num∣n=|\text{num}|.

Output

Print the standard decimal representation, without leading zeros, of the smallest integer obtainable after removing exactly kk digits. Print exactly 0 if its value is zero.

Subtasks

  • Subtask 1 (20 points): 1≤k≤n≤121\le k\le n\le12; num consists of digits 0–9; its first digit is nonzero except when num is 0.
  • Subtask 2 (30 points): 1≤k≤n≤20001\le k\le n\le2000; num consists of digits 0–9; its first digit is nonzero except when num is 0.
  • Subtask 3 (50 points): 1≤k≤n≤1051\le k\le n\le10^5; num consists of digits 0–9; its first digit is nonzero except when num is 0.

Examples

Input

1432219
3

Output

1219

Explanation

For 1432219 and k=3k=3, remove digits 4, 3, and one appropriate 2 while preserving the order of the remaining digits. The resulting sequence is 1219. When scanning the number, each newly encountered smaller digit causes a larger previous digit to be deleted while deletions remain; these three deletions yield the minimum 1219.