Copy Paste

View as PDF

Submit solution

Points: 3
Time limit: 2.0s
Memory limit: 64M

Problem type

A notepad program currently has a string S in it made up of lowercase letters in the english alphabet. The user performs Q actions. Each action, they can either copy a segment of the String into the clipboard or paste what's in the clipboard to the end of the string. After all Q actions, can you figure out what S is?

The specifications for each instruction is given below:

Command Format Description
C a b Copy the segment from a to b into the clipboard
V Paste the string in the clipboard to the end of S

You can also assume that the segment a to b is in S. The first action is guaranteed to be a copy action.


1\le |S|\le 1000

1\le Q\le 1000

1\le a\le b\le |S|

b-a\le 1000

Input Specification

The first line contains the string S.

The second line contains the integer Q.

The next Q lines each describe an action.

Output Specification

One string, the final value of S after all of the actions

Sample Input

C 1 4
C 8 9

Sample Output


Sample Explanation

We start with abcdef. Copying 1-4, we have abcd in the clipboard. Pasting twice, we get abcdefabcdabcd. Copy 8-9, we have bc in the clipboard. Pasting again gives S=abcdefabcdabcdbc


There are no comments at the moment.