159C.md (2118B)
1 Source: https://codeforces.com/problemset/problem/159/C 2 3 C. String Manipulation 1.0 4 5 time limit per test 6 7 3 seconds 8 9 memory limit per test 10 11 256 megabytes 12 13 input 14 15 stdin 16 17 output 18 19 stdout 20 21 One popular website developed an unusual username editing procedure. One can change the username only by deleting some characters from it: to change the current name *s*, a user can pick number *p* and character *c* and delete the *p*-th occurrence of character *c* from the name. After the user changed his name, he can't undo the change. 22 23 For example, one can change name "arca" by removing the second occurrence of character "a" to get "arc". 24 25 Polycarpus learned that some user initially registered under nickname *t*, where *t* is a concatenation of *k* copies of string *s*. Also, Polycarpus knows the sequence of this user's name changes. Help Polycarpus figure out the user's final name. 26 27 Input 28 29 The first line contains an integer *k* (1 ≤ *k* ≤ 2000). The second line contains a non-empty string *s*, consisting of lowercase Latin letters, at most 100 characters long. The third line contains an integer *n* (0 ≤ *n* ≤ 20000) — the number of username changes. Each of the next *n* lines contains the actual changes, one per line. The changes are written as "*p**i* *c**i*" (without the quotes), where *p**i* (1 ≤ *p**i* ≤ 200000) is the number of occurrences of letter *c**i*, *c**i* is a lowercase Latin letter. It is guaranteed that the operations are correct, that is, the letter to be deleted always exists, and after all operations not all letters are deleted from the name. The letters' occurrences are numbered starting from 1. 30 31 Output 32 33 Print a single string — the user's final name after all changes are applied to it. 34 35 Examples 36 37 Input 38 39 ``` 40 2 41 bac 42 3 43 2 a 44 1 b 45 2 c 46 ``` 47 48 Output 49 50 ``` 51 acb 52 ``` 53 54 Input 55 56 ``` 57 1 58 abacaba 59 4 60 1 a 61 1 a 62 1 c 63 2 b 64 ``` 65 66 Output 67 68 ``` 69 baa 70 ``` 71 72 Note 73 74 Let's consider the first sample. Initially we have name "bacbac"; the first operation transforms it into "bacbc", the second one — to "acbc", and finally, the third one transforms it into "acb".