LogiQuest

398. Merge K Sorted Lists

HardHeapMerge

Merge k sorted lists into one sorted list.

Input format

Line 1: k Next k lines: m followed by m sorted integers

Output format

The merged list.

Example 1

Input

3
3 1 4 5
3 1 3 4
2 2 6

Output

1 1 2 3 4 4 5 6

Example 2

Input

1
1 7

Output

7

Constraints

1 ≤ k ≤ 10⁴; total ≤ 10⁵

Read input from standard input and print the answer to standard output. Your code is judged against 3 test cases, most of them hidden.

Loading the MyLoginn IDE…