12111 - sing song   

Description

Bonus problem for 2018 Yang Final Exam

There was a lonely singer called Robert who ordered a beer and wanted to write a new song. 

While he writes his song, he often changes the lyrics. 

 

So he asks you to write a program for him.

There are 4 commands:

1. "w" : write the new line in the nth sentence.

2. "r"  : print out all the lyrics in the newest version. 

3. "a" : append the string after the nth sentence (if the nth sentence is blank, then create it.)

4. "s": swap two sentences

 

Hint:

Input

The first line contains 1 number N, which means the number of instructions. 

Each instruction will be one of the following:

  1. x string: write string at the sentence on x-th line (remove the old data in x-th sentence)
  2. x string: append string at the end of the sentence on x-th line (the sentence might be empty)
  3. r: print out all sentences whose length is > 0 (from sentence on first line to sentence on last line, skip those sentence whose length is 0)
  4. a b: swap the sentence on a-th line and the sentence on b-th line (they might be empty.) 

It's guaranteed that

1. 0 <= x < 10000

2. the length of the "string" in each instruction < 50

3. the total length of each sentence might > 50, because of append

4. N <= 1,000,000

 

Output

If there's a read instruction, output all the setence have so far.

if there's no any words in sentence , do not output anything , even a "\n".

Sample Input  Download

Sample Output  Download

Tags




Discuss