Given a two-dimensional array of integers,
items1 and
items2, representing two sets of elements. Each of these arrays has the following properties:
items[i] = [valuei, weighti] where valuei denotes value and weighti denotes weight   ;ith element;
- the value of each element is unique.
Return a two-dimensional array ret, where ret[i] = [valuei, weighti]< /code>, in which weighti is sum of weights ;all values valuei.
The array ret should be sorted in ascending order by value value.
Input
The program receives as input in the first line an integer n1 - the number of elements in the array
items1. Then n1 lines follow, each of which contains two integers
valuei, weighti - elements of the first array and their weights.< br />
The next line contains the integer n2, the number of elements in the array
items2. Then n2 lines follow, each of which contains two integers
valuei, weighti - elements of the second array and their weights.< br />
Input data restrictions:
1 <= n1, n2 <= 1000
items1[i].len() == items2[i].len() == 2
1 <= valuei, weighti <= 1000
- Each
valuei in items1 unique.
- Each
valuei in items2 unique.
Imprint
Output the
ret array in the required format (see example)
Examples
| # |
Input |
Output |
| 1 |
3
eleven
4 5
3 8
2
3 1
15
|
[[1, 6], [3, 9], [4, 5]]
|
| 2 |
3
eleven
3 2
2 3
3
2 1
3 2
13
|
[[1, 4], [2, 4], [3, 4]]
|