13409 - Make sentences   

Description

There are N students in the class, the teacher wants to play a game with them, the student who makes the longest sentence will win.
But there are rules for making sentences, in this game each operation is randomly drawn, the teacher will randomly select students who can make sentences, and randomly decide what they can do.

There are 5 types of operations:

  1. add x s: Add the string s to the end of the sentence of student x
  2. delete x k: Delete the last k characters word of student x's sentence(do nothing if the sentence is empty)
  3. swap x y: Swap sentences of student x and student y
  4. longest: Output the length of the longest sentence and the sentence, if many students have same length, output the sentence of the student with smallest number.
  5. all: Print all sentences from student 1 to N

Input

The first line contains two integers N, M: the number of students and the number of operations.
The following M lines, each line contains one type of operation.

testcases:

(3/6) 0 < x, y <= N <= 100, 0 < M <= 100, 0 < |s| <= 100 

(3/6) 0 < x, y <= N <= 100, 0 < M <= 10000, 0 < |s| <= 100

Note that: s is the string to be added during the add operation, the length of student's sentence may exceed 100.

Note: Please use malloc() and free() properly.

Output

See the description

 

Sample Input  Download

Sample Output  Download

Tags




Discuss