#K4556. Shopping List Simulation

    ID: 27780 Type: Default 1000ms 256MiB

Shopping List Simulation

Shopping List Simulation

You are given a series of commands that manipulate a shopping list. The shopping list starts empty and supports three commands:

  • ADD <item>: Add the item to the shopping list.
  • REMOVE <item>: Remove the item from the shopping list if it exists.
  • PRINT: Print the current shopping list in lexicographical order (i.e., sorted order), with each item on a new line. If the list is empty, print EMPTY.

For example, given the following commands:

ADD milk
ADD bread
PRINT

The shopping list contains "milk" and "bread". After sorting these lexicographically, the output will be:

bread
milk

Process each command in the order given. Every time a PRINT command is encountered, output the shopping list as described. Note that if an item is attempted to be removed that does not exist in the list, nothing happens.

All commands are case-sensitive.

inputFormat

The input is read from standard input (stdin) and follows this format:

  1. The first line contains an integer N, representing the number of commands.
  2. The next N lines each contain a command which is one of the following forms:
    • ADD <item>
    • REMOVE <item>
    • PRINT

outputFormat

For each PRINT command in the input, output the current state of the shopping list:

  • If the list is non-empty, print the items in lexicographical (alphabetical) order, with each item on its own line.
  • If the list is empty, print EMPTY.

All outputs should be written to standard output (stdout) in the order the PRINT commands appear.

## sample
3
ADD milk
ADD bread
PRINT
bread

milk

</p>