#C3180. Total Sales Calculation for Common Products

    ID: 46579 Type: Default 1000ms 256MiB

Total Sales Calculation for Common Products

Total Sales Calculation for Common Products

You are given sales data for two weeks separated by an empty line. Each line in a week consists of a product identifier and its sales amount, separated by a comma. Note that a product can have multiple entries within the same week, and you should sum these amounts.

Your task is to compute the total sales for every product that appears in both weeks. The output should list these products in ascending order of their product identifier, and for each product, output the product id and the combined total sales separated by a space. If there is no product common to both weeks, output nothing.

You may assume the following about the input:

  • The two weeks are separated by a blank line.
  • Each non-empty line consists of two integers separated by a comma: the first integer represents the product id and the second the sales amount.

The solution involves reading the input from stdin and printing the results to stdout. In mathematical terms, if S1(i) is the total sales for product i in the first week and S2(i) in the second week, then for each product i that appears in both weeks, output:

iS1(i)+S2(i)i \quad S_{1}(i)+S_{2}(i)

inputFormat

The input is read from stdin and consists of two sections separated by a blank line. Each section contains one or more lines of the form:

product_id,sales_amountproduct\_id,sales\_amount

There is no extra delimiter other than the blank line between the two weeks’ data.

outputFormat

For each product that appears in both weeks, output a single line containing the product id and the sum of its sales across the two weeks, separated by a space. The products must be listed in ascending order of product id. If no product is present in both weeks, output nothing.

## sample
101,500
202,3000
303,200

101,700
202,2000
404,100
101 1200

202 5000

</p>