#C5866. Restock Shoes Inventory

    ID: 49562 Type: Default 1000ms 256MiB

Restock Shoes Inventory

Restock Shoes Inventory

You are given two inventory reports for a shoe store. Each report lists shoe models and their corresponding quantities. The first report has n entries and the second has m entries. Your task is to calculate the deficit for each shoe model by comparing the quantities in the two reports.

For a given shoe model:

  • If the model appears in both reports and the quantities differ, the deficit is given by the absolute difference \( |a - b| \), where \( a \) and \( b \) are the quantities in the first and second reports respectively.
  • If the model appears in only one report, then the deficit is the quantity provided in that report.
  • If the quantities are identical for models that appear in both reports, no output is produced for that model.

Your final answer should list out each affected shoe model along with its deficit, sorted in ascending order of shoe model IDs. Input should be read from standard input (stdin) and output printed to standard output (stdout).

inputFormat

The input is given in the following format from stdin:

<n>
model_1 quantity_1
model_2 quantity_2
... (n lines)
<m>
model_1 quantity_1
model_2 quantity_2
... (m lines)

\(n\) and \(m\) are integers representing the number of entries in the first and second inventory lists respectively. Each subsequent line contains a shoe model ID (an integer) followed by its quantity (an integer), separated by space.

outputFormat

For each shoe model that requires restocking, print a line with the model ID and the deficit quantity separated by a space. The output should be sorted in ascending order of the model IDs. If no restocking is needed (i.e. the inventories are identical), output nothing.

Output should be sent to stdout.

## sample
5
101 10
102 5
103 20
104 15
105 8
6
101 5
103 25
106 10
105 10
107 3
108 7
101 5

102 5 103 5 104 15 105 2 106 10 107 3 108 7

</p>