#K46242. Update Stock Levels

    ID: 27933 Type: Default 1000ms 256MiB

Update Stock Levels

Update Stock Levels

You are given the current stock levels of various items and a list of transactions. Each transaction consists of an item and a quantity change. Your task is to update the stock levels accordingly. If a transaction refers to an item not present in the stock, add it with the given quantity. The updated stock for any item is given by the formula (new_stock = old_stock + change).

For example, if the stock of an item is 10 and the transaction specifies a change of -3, then the updated stock will be 7.

inputFormat

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

Line 1: An integer (n) representing the number of items in the initial stock.
Next (n) lines: Each line contains a string (item name) and an integer (its stock level), separated by space.
Next line: An integer (m) representing the number of transactions.
Next (m) lines: Each line contains a string (item name) and an integer (quantity change), separated by space.

outputFormat

Print the updated stock levels as a JSON formatted dictionary on standard output (stdout). The keys are item names and the values are the updated stock numbers. The order of keys does not matter.## sample

3
apple 10
banana 5
orange 8
4
apple -3
banana 2
orange -5
grape 7
{"apple": 7, "banana": 7, "orange": 3, "grape": 7}