#K11721. Inventory Management System

    ID: 23532 Type: Default 1000ms 256MiB

Inventory Management System

Inventory Management System

You are given an initial inventory of products and a sequence of update operations. The inventory is represented as a list of product IDs (which are strings). Each update operation is either an addition or a removal of a product from the inventory.

For each operation:

  • ADD: Append the product ID to the inventory.
  • REMOVE: Remove the first occurrence of the product ID from the inventory if it exists.

Finally, sort the inventory in lexicographical order. If the final inventory is empty, output EMPTY.

Note: Duplicate product IDs are allowed and are treated as separate entries.

inputFormat

The input is given via standard input (stdin) with the following format:

n
p1 p2 ... pn
m
op1 product1
op2 product2
...
opm productm

Here, n is the number of products in the initial inventory. If n > 0, the next line contains n space-separated product IDs.

Then, m is the number of update operations, followed by m lines. Each operation line contains an operation (either ADD or REMOVE) and a product ID.

outputFormat

The output should be printed to standard output (stdout). Print the final inventory as a single line with the product IDs sorted lexicographically and separated by a single space. If the inventory is empty, print EMPTY (without quotes).

## sample
5
ABC123 XYZ234 LMN456 ABC123 JKL789
4
REMOVE ABC123
ADD DEF001
REMOVE LMN456
ADD XYZ234
ABC123 DEF001 JKL789 XYZ234 XYZ234