n=int(eval(input()))-1

A=list(map(int,input().split()))

i=0

for j in range(n):

 if A[j]<=A[-1]:A[i],A[j]=A[j],A[i];i+=1

A[i],A[n]='['+str(A[n])+']',A[i]

print((*A))

n=int(eval(input()))-1

A=list(map(int,input().split()))

i=0;x=A[-1]

for j in range(n):

 if A[j]<=x:A[i],A[j]=A[j],A[i];i+=1

A[i],A[n]='['+str(A[n])+']',A[i]

print((*A))

n = int(eval(input())) - 1
A = list(map(int, input().split()))
i = 0
for j in range(n):
    if A[j] <= A[-1]:
        A[i], A[j] = A[j], A[i]
        i += 1
A[i], A[n] = "[" + str(A[n]) + "]", A[i]
print((*A))

n = int(eval(input())) - 1
A = list(map(int, input().split()))
i = 0
x = A[-1]
for j in range(n):
    if A[j] <= x:
        A[i], A[j] = A[j], A[i]
        i += 1
A[i], A[n] = "[" + str(A[n]) + "]", A[i]
print((*A))

+x = A[-1] -    if A[j] <= A[-1]: +    if A[j] <= x: