#K54002. Inventory Update

    ID: 29656 Type: Default 1000ms 256MiB

Inventory Update

Inventory Update

You are given the initial inventory of several products, along with a series of supply and sales transactions. Your task is to compute the final inventory count for every product. For each product, the final inventory is calculated as follows:

$$ final = initial + \sum_{i=1}^{supply} supply_i - \sum_{j=1}^{sales} sales_j $$

If a product is not present in the initial inventory, assume its initial count is zero. The final result should list every product that appears in any transaction, sorted in lexicographical order.

inputFormat

The input is read from standard input and is formatted as follows:

  1. The first line contains an integer (n) denoting the number of products in the initial inventory.
  2. The following (n) lines each contain a product name (a single word) and an integer representing its initial count, separated by a space.
  3. Next, a line with an integer (s) is given, representing the number of supply transactions.
  4. The next (s) lines each provide a product name and an integer (the supply count), separated by a space.
  5. Then, a line with an integer (m) is provided, representing the number of sales transactions.
  6. The following (m) lines each contain a product name and an integer (the sale count), separated by a space.

outputFormat

For each product in the final inventory, output a single line with the product name and its final count separated by a space. The products must be printed in lexicographical order.## sample

2
bread 10
milk 5
2
bread 5
cookie 10
2
milk 2
bread 7
bread 8

cookie 10 milk 3

</p>