#K5821. Inventory Update Tracker

    ID: 30592 Type: Default 1000ms 256MiB

Inventory Update Tracker

Inventory Update Tracker

You are given a series of inventory update operations for products identified by unique IDs. Each update operation consists of a product ID and a change in the inventory (which can be positive, negative, or zero). Your task is to process these operations in sequence and report the final inventory counts for products that have a nonzero inventory.

For each operation, update the inventory of the corresponding product. If the resulting inventory becomes zero, remove that product from your records. The final output should list every product with a nonzero inventory, sorted in ascending order by product ID.

Formally, if you denote the inventory for a product with ID i as \(I_i\), and an operation updates it by \(\Delta\), then the update is given by:

[ I_i = I_i + \Delta ]

If \(I_i = 0\) after any update, the product should not appear in the final list.

inputFormat

The input is read from stdin and has the following format:

n
id1 change1
id2 change2
... (n lines in total)

Here, n is the number of inventory update operations. Each of the following n lines contains two integers: id (the product's unique identifier) and change (the change in inventory).

outputFormat

Output to stdout the final nonzero inventory records. For each product, print a line with the product ID and the inventory count separated by a space. The records must be printed in ascending order of the product IDs. If no product has a nonzero inventory, output nothing.

## sample
5
1001 5
1002 -2
1001 3
1003 4
1002 3
1001 8

1002 1 1003 4

</p>