lst = []
def f(wait,stack,out):
    if wait:
        f(wait[1:],stack+[wait[0]],out)
    if stack:
        f(wait,stack[:-1],out+[stack[-1]])
    if not wait and not stack:
        lst.append(' '.join(map(str,out)))
    

N = int(input())
ls = list(map(int,input().split()))
f(ls,[],[])

lst.sort()
for i in lst:
    print(i)