COD love!! [Medium]

4.1

7 votes
Medium
Problem

Gurpreet and Shyamu were playing COD(yes you read right that is Call of Duty). As you all know Gurpreet is too good in it. Shyamu being jealous give Gurpreet a problem to solve so that he can clear more missions than him.
The Problem is :
Shyamu gives Gurpreet a string str and q queries.
Each query is of type

k ch
(where k is a positive number and ch is a lowercase character)

In each query Gurpreet has to delete kth occurence of character ch. And at the end he has to print the string after all queries. As Gurpreet wants to play COD he give this task to you to solve.

Input :

The first line contains string str, and second line contains q that is number of queries.
Then q lines consist of queries as above explained.

Output :

A String in single line after performing all queries.

Constraints :

1 <= length(str) <= 2*105
1 <= q <= 5*
105

Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

Given String is agcdgcaag. Here
char : frequency
a : 3
g : 3
c : 2
d : 1
hence after 1st query string is : agcdgcag
query 2: agdgcag
query 3: aggcag
query 4: aggca
query 5: aggc

Editor Image

?