## An Animal Contest 4 P1 - Dasher's Digits

View as PDF

Points: 5 (partial)
Time limit: 2.0s
Memory limit: 256M

Author:
Problem type

Dasher the reindeer has a string with characters, where characters are 0's and the rest are uppercase Latin letters. Each 0 is assigned a "cheer value" . The cheer values are where corresponds to the cheer value for the first 0 in , the cheer value for the second 0, and so on.

Dasher wants to get rid of all the 0's in his string, so he performs the following algorithm while there are still 0's present:

• If the frontmost character is 0, subtract that 0's cheer value by . If this cheer value becomes , remove this 0. Otherwise, move it, along with its cheer value, to the back of the string.

• Otherwise, take the frontmost character and move it to the back of the string.

For strings that are extensive in length, performing the algorithm manually is a tedious process. Dasher requires your assistance to output the string after all 0's have been removed through the usage of the mentioned algorithm.

#### Constraints

contains at least one non-0 character.

#### Input Specification

The first line will contain two space-separated integers and .

The second line will contain , which has at least one non-0 character, and may contain leading 0's.

The next line will contain space-separated integers .

#### Output Specification

Output the string after all 0's are removed with the algorithm described.

#### Sample Input

7 1
US0AMOG
2

#### Sample Output

AMOGUS

#### Explanation

The following shows the results of performing the algorithm manually to obtain our answer:

US0AMOGS0AMOGU0AMOGUSAMOGUS0MOGUS0AOGUS0AMGUS0AMOUS0AMOGS0AMOGU0AMOGUSAMOGUS