N = int(input())
num = list(input().split(" "))

# 本质是回溯法
def dfs(num, i, stack, out):
    if i >= len(num) and len(stack) == 0:
        ans.append(" ".join(out))
        return

    # 火车入站
    if i < len(num):
        stack.append(num[i])
        dfs(num, i+1, stack, out)
        stack.pop()

    # 火车出站
    if len(stack) > 0:
        out.append(stack.pop())
        dfs(num, i, stack, out)
        stack.append(out.pop())
        
ans = []
dfs(num, 0, [], [])
for s in sorted(ans):
    print(s)