#C11310. Update Inventory

    ID: 40613 Type: Default 1000ms 256MiB

Update Inventory

Update Inventory

You are given two lists: an inventory and a shipment. Each list contains several items, where each item is represented by an identifier (a string) and a quantity (an integer). Your task is to update the inventory with the shipment.

The update should be done as follows:

If an item from the shipment already exists in the inventory, add the shipment quantity to the inventory quantity. Otherwise, add the new item from the shipment to the inventory.

The final updated inventory should be output sorted in lexicographical order by item identifier. Note that while the problem involves simple addition, you can consider the update formula as follows: \( Q_{new} = Q_{old} + Q_{shipment} \), where \( Q_{old} \) and \( Q_{shipment} \) are integer quantities.

This is a typical problem that tests your ability to perform dictionary (or map) manipulations and sorting.

inputFormat

The first line of input contains an integer ( n ) representing the number of items in the inventory. Each of the following ( n ) lines contains a string and an integer separated by space, representing the identifier and quantity of an item in the inventory.

The next line contains an integer ( m ) representing the number of shipment items. Each of the following ( m ) lines contains a string and an integer separated by space, representing the identifier and quantity of an item in the shipment.

outputFormat

Output the updated inventory. For each item, print a line containing the identifier and its updated quantity separated by a space. The items must be listed in lexicographical order by their identifier.## sample

3
apple 10
banana 5
orange 7
3
banana 3
orange 2
grapefruit 4
apple 10

banana 8 grapefruit 4 orange 9

</p>