P5250 [Deep Basic 17. Example 5] Timber Warehouse

Description

In Boai City, there is a timber warehouse that can store timber of various lengths, and it is guaranteed that no two pieces of timber have the same length. As the warehouse manager, you sometimes purchase stock and sometimes ship stock, so you need to maintain the inventory. There are no more than $10^5$ operations: - Stock in, format `1 Length`: Put a piece of timber of length $Length$ (no more than $10^9$) into the warehouse. If a piece of timber with the same length already exists, output `Already Exist`. - Stock out, format `2 Length`: Take out the piece of timber with length $Length$ from the warehouse. If there is no piece with exactly that length, take out the piece in the warehouse whose length is closest to the requested length. If multiple pieces satisfy this, take out the shorter one. Output the length of the timber taken out. If the warehouse is empty, output `Empty`.

Input Format

The first line contains an integer $m$, representing the number of operations. The next $m$ lines each contain one operation, in the format described in the statement.

Output Format

For each operation, output the answer as required in the statement.

Explanation/Hint

Translated by ChatGPT 5