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

#GD0000196. Xâu không rẻ (Not a Cheap String)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Xâu không rẻ (Not a Cheap String)

Not a Cheap String

Source: Codeforces

Version: Phuoc Hung OJ Extended

Problem Statement

The price of a lowercase English string is the sum of the values of its letters: a costs 11, b costs 22, and so on through z, which costs 2626. Repeated occurrences contribute their costs separately. For example, abca costs 1+2+3+1=71+2+3+1=7.

You are given a string ww and a budget pp. You may delete characters at arbitrary positions, but the relative order of all remaining characters must stay unchanged. The resulting string must have a total price at most pp.

Keep as many characters as possible and print the resulting string. Any maximum-length valid string is accepted. The result may be empty. If the original string already costs at most pp, it must be printed unchanged.

Input

  • The first line contains a lowercase English string ww.
  • The second line contains an integer pp, the maximum allowed total price.

Output

Print one line containing a longest subsequence of ww whose total price does not exceed pp. Print an empty line if no character can be kept.

Subtasks

  • Subtask 1 (20 points): 1≤∣w∣≤201\le |w|\le 20; 1≤p≤5 200 0001\le p\le 5\,200\,000; Every character of ww is in a–z.
  • Subtask 2 (30 points): 1≤∣w∣≤20001\le |w|\le 2000; 1≤p≤5 200 0001\le p\le 5\,200\,000; Every character of ww is in a–z.
  • Subtask 3 (50 points): 1≤∣w∣≤2⋅1051\le |w|\le 2\cdot10^5; 1≤p≤5 200 0001\le p\le 5\,200\,000; Every character of ww is in a–z.

Examples

Input

abca
2

Output

aa

Explanation

The original string abca costs 1+2+3+1=71+2+3+1=7, exceeding p=2p=2. Keeping the first and last a produces aa at price 1+1=21+1=2. Keeping three characters is impossible because even the three cheapest occurrences cost 1+1+2=4>21+1+2=4>2. Thus the maximum length is 22.