#C9181. Warehouse Operations

    ID: 53246 Type: Default 1000ms 256MiB

Warehouse Operations

Warehouse Operations

In a large warehouse, packages are managed within boxes. Each box is labeled by a unique name and contains a certain number of packages. You are given a list of initial boxes, each with its initial package count, and a series of operations to perform. The operations consist of:

  • ADD <box> <count>: Add count packages to the specified box.
  • REMOVE <box> <count>: Remove count packages from the specified box. The package count cannot become negative.
  • MOVE <source> <destination>: Move all packages from the source box to the destination box. If the destination box does not exist, create it with an initial count of 0 before transferring the packages, and then set the source's package count to 0.
  • QUERY <box>: Output the number of packages in the specified box. If the box does not exist, treat its count as 0.

All operations are performed sequentially. Note that the final output comprises the results of all QUERY operations in the order they appear.

For any mathematical representation, you may use LaTeX. For instance, the package count should always satisfy \( \text{count} \ge 0 \).

inputFormat

The input is read from the standard input (stdin) in the following format:

  1. An integer n, representing the number of initial boxes.
  2. n lines follow, each containing a string and an integer separated by a space, which represent the box name and its initial number of packages.
  3. An integer m, representing the number of operations.
  4. m lines follow, each containing a command in one of the following forms:
    • ADD <box> <count>
    • REMOVE <box> <count>
    • MOVE <source> <destination>
    • QUERY <box>

outputFormat

For each QUERY operation encountered in the input, output the number of packages in the specified box on a separate line (stdout).

## sample
3
BoxA 10
BoxB 20
BoxC 30
7
ADD BoxA 5
REMOVE BoxB 15
MOVE BoxA BoxC
QUERY BoxA
QUERY BoxB
QUERY BoxC
ADD BoxD 10
0

5 45

</p>