Dasher the reindeer has a string 0
's and the rest are uppercase Latin letters. Each 0
is assigned a "cheer value" 0
in 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 that0
's cheer value by . If this cheer value becomes , remove this0
. 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
0
character.
Subtask 1 [20%]
Subtask 2 [30%]
Subtask 3 [50%]
No additional constraints.
Input Specification
The first line will contain two space-separated integers
The second line will contain 0
character, and may contain leading 0
's.
The next line will contain
Output Specification
Output the string 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:
US0AMOG
→ S0AMOGU
→ 0AMOGUS
→ AMOGUS0
→ MOGUS0A
→ OGUS0AM
→ GUS0AMO
→ US0AMOG
→ S0AMOGU
→ 0AMOGUS
→ AMOGUS
Comments
Bro why am I getting tle on a linear time solution
6 1
UGH0RO
1
AMONGUS SUS