598B.md (1679B)
1 Source: https://codeforces.com/problemset/problem/598/B 2 3 B. Queries on a String 4 5 time limit per test 6 7 2 seconds 8 9 memory limit per test 10 11 256 megabytes 12 13 input 14 15 standard input 16 17 output 18 19 standard output 20 21 You are given a string *s* and should process *m* queries. Each query is described by two 1-based indices *l**i*, *r**i* and integer *k**i*. It means that you should cyclically shift the substring *s*[*l**i*... *r**i*] *k**i* times. The queries should be processed one after another in the order they are given. 22 23 One operation of a cyclic shift (rotation) is equivalent to moving the last character to the position of the first character and shifting all other characters one position to the right. 24 25 For example, if the string *s* is abacaba and the query is *l*1 = 3, *r*1 = 6, *k*1 = 1 then the answer is abbacaa. If after that we would process the query *l*2 = 1, *r*2 = 4, *k*2 = 2 then we would get the string baabcaa. 26 27 Input 28 29 The first line of the input contains the string *s* (1 ≤ |*s*| ≤ 10 000) in its initial state, where |*s*| stands for the length of *s*. It contains only lowercase English letters. 30 31 Second line contains a single integer *m* (1 ≤ *m* ≤ 300) — the number of queries. 32 33 The *i*-th of the next *m* lines contains three integers *l**i*, *r**i* and *k**i* (1 ≤ *l**i* ≤ *r**i* ≤ |*s*|, 1 ≤ *k**i* ≤ 1 000 000) — the description of the *i*-th query. 34 35 Output 36 37 Print the resulting string *s* after processing all *m* queries. 38 39 Examples 40 41 Input 42 43 ``` 44 abacaba 45 2 46 3 6 1 47 1 4 2 48 ``` 49 50 Output 51 52 ``` 53 baabcaa 54 ``` 55 56 Note 57 58 The sample is described in problem statement.