eval(input())

A=[0]+list(map(int,input().split()))

H=len(A)

def h(i):

 l=2*i;r,g=l+1,[i,l][l<H and A[i]<A[l]]

 if r<H and A[g]<A[r]:g=r

 if g!=i:A[i],A[g]=A[g],A[i];h(g)

for i in range(H//2,0,-1):h(i)

a=''

for s in A[1:]:a+=f' {s}'

print(a)

eval(input())

A=[0]+list(map(int,input().split()))

H=len(A)

def h(i):

 l=2*i;r,g=l+1,[i,l][l<H and A[i]<A[l]]

 if r<H and A[g]<A[r]:g=r

 if g!=i:A[i],A[g]=A[g],A[i];h(g)

for i in range(H//2,0,-1):h(i)

print((' '+' '.join(map(str,A[1:]))))

eval(input())
A = [0] + list(map(int, input().split()))
H = len(A)


def h(i):
    l = 2 * i
    r, g = l + 1, [i, l][l < H and A[i] < A[l]]
    if r < H and A[g] < A[r]:
        g = r
    if g != i:
        A[i], A[g] = A[g], A[i]
        h(g)


for i in range(H // 2, 0, -1):
    h(i)
a = ""
for s in A[1:]:
    a += f" {s}"
print(a)

eval(input())
A = [0] + list(map(int, input().split()))
H = len(A)


def h(i):
    l = 2 * i
    r, g = l + 1, [i, l][l < H and A[i] < A[l]]
    if r < H and A[g] < A[r]:
        g = r
    if g != i:
        A[i], A[g] = A[g], A[i]
        h(g)


for i in range(H // 2, 0, -1):
    h(i)
print((" " + " ".join(map(str, A[1:]))))

-a = "" -for s in A[1:]: -    a += f" {s}" -print(a) +print((" " + " ".join(map(str, A[1:]))))