Remove segments from a linked list

Given a linked list, you are asked to execute q queries on it. There are 2 types of queries:
  1. print - the program should print the linked list
  1. remove l r - remove all the elements starting from l-th and ending at r-th both inclusive.


The initial data for the linked list is obtained automatically. You don’t need to do anything. It’s guaranteed that the size of the linked list does not exceed 1000 and the values in the linked list do not exceed in their absolute value.
The first line of the input contains a single integer q (1 ≤ q ≤ 1000).
The next q lines contain the queries - print in case the program should print the linked list, and remove l r if the program should remove the values between the l-th and the r-th elements (1 ≤ l, r ≤ |L|).


The program should correctly print the values in the linked list for all the print queries. The values should be separated by spaces.


10 4 8 4 0 -2 8 2 8 0 4 5 remove 1 2 print remove 1 2 remove 3 4 print
4 0 -2 8 2 8 0 4 -2 8 0 4


Time limit: 2.4 seconds

Memory limit: 512 MB

Output limit: 1 MB

To check your solution you need to sign in