Problem 08B. Merge K Sorted Arrays ≡

Author:Pavel Mesenev   Time limit:2 sec
Input file:Standard input   Memory limit:256 Mb
Output file:Standard output  

Statement

You are given k arrays, each already sorted in non-decreasing order (an array may be empty). Output all elements from all arrays, merged into one non-decreasing sequence.

Input format

The first line contains one integer k. Then, for each of the k arrays: one line with its length m, followed by a line with m space-separated integers (the line may be empty if m = 0).

Output format

Print all elements, merged and sorted, space-separated on one line (an empty line if there are none).

Constraints

1 ≤ k ≤ 2 ⋅ 105

0 ≤  total number of elements across all arrays  ≤ 2 ⋅ 105

 − 109 ≤ element ≤ 109

Sample tests

No. Standard input Standard output
1
3
3
1 4 5
3
1 3 4
2
2 6
1 1 2 3 4 4 5 6
2
1
4
1 2 3 4
1 2 3 4

0.043s 0.011s 16