# wait:等待进站 #stack:进站列表 #out:出站列表 def f(wait,stack,out): if not wait and not stack: # 所有的车都出站了,即wait和stack均为空,空本身就是false,not空=true res.append(' '.join(out)) if wait: #如果有车在等待 f(wait[1:],stack+[wait[0]],out) #进站 if stack: f(wait,stack[:-1],out+[stack[-1]]) #出站,用+连接两个列表 n = int(input()) #火车数量 num = input().split() res = [] # 存放出站编号 f(num,[],[]) # 排序后输出 for i in sorted(res): print(i)