题目描述
Problem Description
Translated from COCI 2009.11 T6 "PASIJANS"
Given \( N \) stacks with numbers already inserted (each stack may have a different number of elements), there is an empty "answer queue". You can perform the operation "pop the top element from a stack and insert it at the end of the answer queue" until all stacks are emptied. Find the lexicographically smallest answer queue.
If two answer queues \( a \) and \( b \) are identical for the first \( i-1 \) elements but \( a_i < b_i \), then \( a \) is lexicographically smaller than \( b \).
Input Format
The first line contains an integer \( N \).
The next \( N \) lines each start with an integer \( L \), indicating the number of elements in the stack. Following this, \( L \) integers are given in the order from top to bottom of the stack.
Output Format
Output \( \sum L \) integers, representing the lexicographically smallest answer queue.
Sample Input and Output
Sample Input #1
3
1 2
1 100
1 1
Sample Output #1
1 2 100
Sample Input #2
2
5 10 20 30 40 50
2 28 27
Sample Output #2
10 20 28 27 30 40 50
Sample Input #3
2
3 5 1 2
3 5 1 1
Sample Output #3
5 1 1 5 1 2
Notes
\( 1 \le N \le 1000 \), \( 1 \le L \le 1000 \).
输入格式
见题面 Input 部分
输出格式
见题面 Output 部分