#C1960. List Manipulation with Commands
List Manipulation with Commands
List Manipulation with Commands
List Manipulation with Commands
You are given an initially empty list of integers. Your task is to process a sequence of commands to manipulate the list. There are four kinds of commands:
- Append X: Append the integer X to the end of the list.
- Insert Y Z: Insert the integer Y at index Z in the list. If index Z is out of bounds, append Y to the end of the list.
- DeleteLast: Remove the last element of the list if the list is not empty.
- DeleteFirst X: Remove the first occurrence of the integer X from the list if it exists.
If at the end of processing all commands the list is empty, output Empty
instead.
Note: Any command that does not exactly match the formats above should be ignored.
The commands are provided via standard input.
inputFormat
The first line contains a single integer N representing the number of commands.
The following N lines each contain a command as described above.
Examples of commands: Append 4
, Insert 7 1
, DeleteLast
, DeleteFirst 5
.
outputFormat
If the list is not empty, output the space-separated integers representing the final state of the list.
If the list is empty, output the string Empty
.
3
Append 1
Append 2
Append 3
1 2 3