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

#GD0000146. Bài toán trên bảng (Task On The Board)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Bài toán trên bảng (Task On The Board)

Task On The Board

Source: Codeforces

Version: Phuoc Hung OJ Extended

Problem Statement

A lowercase string ss has been processed by deleting some characters and rearranging the remaining characters into an unknown string tt of length mm. For each position ii you are given bib_i: the sum of distances ∣i−j∣|i-j| over all positions jj where tjt_j is alphabetically larger than tit_i.

Find any string tt consistent with the data. A solution is guaranteed to exist.

Input

The first line contains the lowercase string ss. The second line contains mm. The third line contains mm integers bib_i.

Output

Print a lowercase string tt of length mm, made from available occurrences in ss, that satisfies every distance sum bib_i.

Subtasks

  • Subtask 1 (20 points): 1≤∣s∣≤81\le|s|\le8; 1≤m≤∣s∣1\le m\le|s|; s∈{a,…,z}∣s∣s\in\{a,\ldots,z\}^{|s|}; 0≤bi≤12250\le b_i\le1225; a solution exists.
  • Subtask 2 (30 points): 1≤∣s∣≤251\le|s|\le25; 1≤m≤∣s∣1\le m\le|s|; s∈{a,…,z}∣s∣s\in\{a,\ldots,z\}^{|s|}; 0≤bi≤12250\le b_i\le1225; a solution exists.
  • Subtask 3 (50 points): 1≤∣s∣≤501\le|s|\le50; 1≤m≤∣s∣1\le m\le|s|; s∈{a,…,z}∣s∣s\in\{a,\ldots,z\}^{|s|}; 0≤bi≤12250\le b_i\le1225; a solution exists.

Examples

Input

abba
3
1 0 1

Output

aba

Explanation

The string aba can be formed from abba. The first and last a are each one position away from the larger character b, so b1=b3=1b_1=b_3=1; the middle b has no larger character, so b2=0b_2=0.