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:
||Copy the segment from ~a~ to ~b~ into the clipboard|
||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|~
The first line contains the string ~S~.
The second line contains the integer ~Q~.
The next ~Q~ lines each describe an action.
One string, the final value of ~S~ after all of the actions
abcdef 5 C 1 4 V V C 8 9 V
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=~