407762: GYM102890 M Mathematics society problem

Memory Limit:256 MB Time Limit:1 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

M. Mathematics society problemtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard output

Nlogonia secret mathematics society helds meetings with distinguished members that are able to solve a given mathematical problem. Being one of the most prestigious mathematics societies in the region you want to participate in the meeting, they discuss in this meetings a lot of interesting problems and their solutions, and therefore, it could be also a very good place to train your algorithmic skills.

The problem to be invited to the next meeting has been posted, last month meeting they used an interesting problem that generated long lists of numbers. This time, they want you to work with some of these numbers. They will give you a number $$$N$$$ that contains only digits from $$$1$$$ to $$$9$$$, your task is to remove a specified amount of each digit from $$$N$$$ and get the biggest possible number. Will you be able to join this month meeting?

Input

The first line of input contains a number $$$N$$$, $$$N$$$ will have at most $$$1000$$$ digits. The second and last line of input contains $$$9$$$ integer numbers separated by a space, where the $$$i$$$-th number represents the amount of times the digit $$$i$$$ should be removed from $$$N$$$. It is guaranteed that no digit should be removed more times than it appears in $$$N$$$, and that in no case all digits from $$$N$$$ should be removed.

Output

Output a line containing a number, representing the biggest number you can get after removing the specified digits from $$$N$$$.

ExamplesInput
12345
1 0 0 1 1 0 0 0 0
Output
23
Input
112345
2 1 1 0 0 0 0 0 0
Output
45
Input
54321
0 0 0 0 0 0 0 0 0
Output
54321

加入题单

算法标签: