# Process input
n = int(input())
ax = input().split()
# DFS
def dfs(arr, i, station, seq, orders):
if i == len(arr) and not station:
orders.append(' '.join(seq))
return
if i < len(arr):
station.append(arr[i])
dfs(arr, i+1, station, seq, orders)
station.pop()
if station:
train = station.pop()
seq.append(train)
dfs(arr, i, station, seq, orders)
seq.pop()
station.append(train)
res = []
dfs(ax, 0, [], [], res)
# Output
res.sort()
for row in res:
print(row)



京公网安备 11010502036488号