#C3386. Sequence Operation Processor
Sequence Operation Processor
Sequence Operation Processor
You are given a sequence of operations to modify a list of numbers. Initially, the sequence is empty. There are two types of operations:
- add x: Append the integer x to the end of the sequence.
- remove k: Remove the kth element from the sequence (1-indexed) if it exists.
After applying all operations, output the final sequence of numbers as a space-separated string. If the sequence is empty, output empty
.
Note: The operations must be processed in the order they are given.
The formula for a removal operation (if valid) can be understood as: $$sequence = [a_1,a_2,\dots,a_{k-1},a_{k+1},\dots,a_n]$$
inputFormat
The input is read from stdin and is formatted as follows:
- The first line contains a single integer N representing the number of operations.
- The next N lines each contain an operation, which is either "add x" or "remove k".
outputFormat
Print to stdout the final sequence of numbers after processing all operations. The numbers should be separated by a single space. If the sequence is empty, print empty
.
6
add 5
add 3
add 10
remove 2
add 7
remove 1
10 7