#K9826. Process List Operations
Process List Operations
Process List Operations
You are given an initially empty list and a sequence of n operations. Your task is to process these operations sequentially and output the final state of the list.
The operations can be one of the following:
append x
: Append integer \(x\) to the end of the list.insert i x
: Insert integer \(x\) at index \(i\) (0-indexed).remove x
: Remove the first occurrence of integer \(x\) from the list.pop
: Remove the last element of the list if it exists.reverse
: Reverse the list.extend [a, b, ...]
: Extend the list by appending the integers contained in the given bracketed list.
After processing all operations, if the list is not empty, output the elements of the list separated by a single space. Otherwise, output Empty
.
Note: All operations are case sensitive. Use standard input/output for reading and writing data.
inputFormat
The first line contains an integer \(n\) (\(1 \le n \le 1000\)), the number of operations.
The next \(n\) lines each contain a string describing an operation as specified above.
Example:
6 append 3 append 4 insert 1 5 remove 3 reverse extend [6, 7]
outputFormat
If the list is non-empty after processing all operations, output the elements of the list separated by a single space.
If the list is empty, output Empty
.
Example Output:
4 5 6 7## sample
3
append 3
append 4
insert 1 5
3 5 4
</p>