An accounting system keeps K ledgers, each a singly linked chain of amounts sorted in non-decreasing order. Fuse all K chains into a single chain that is also sorted in non-decreasing order, keeping every amount (including duplicates across chains).
Input format
Line 1: an integer K, the number of chains.
Then, for each chain in turn, two lines:
- a line with an integer
L, the chain's length; - a line with
Lspace-separated integers in non-decreasing order (empty line whenLis 0).
Output format
Line 1: the total number of amounts across all chains. Line 2: all amounts merged into non-decreasing order, space-separated (empty line if there are none).
Constraints
- 1 <= K <= 50
- 0 <= each chain length, and the total number of amounts <= 100000.
- Each chain is given in non-decreasing order.
- -1000000000 <= each amount <= 1000000000