n = int(eval(input()))

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

x = lst_n[n-1]

left  = []

right = []

i = -1

for j in range(0,n-1):

    if lst_n[j] <= x:

        i += 1

        lst_n[i],lst_n[j] = lst_n[j],lst_n[i]

i += 1

lst_n[i],lst_n[n-1] = lst_n[n-1],lst_n[i]



ans = ['['+str(lst_n[k])+']' if k == i else str(lst_n[k])

        for k in range(len(lst_n))]

print((' '.join(ans)))

def partition(lst,start,last):

    x = lst[last]

    i = start

    for j in range(start,last):

        if lst[j] <= x:

            lst[i],lst[j] = lst[j],lst[i]

            i += 1

    lst[i],lst[last] = lst[last],lst[i]

    return i



n = int(eval(input()))

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

p = partition(n_lst,0,n-1)

str_lst = list(map(str,n_lst))

str_lst[p] = '['+str_lst[p]+']'

print((' '.join(str_lst)))

n = int(eval(input()))
lst_n = list(map(int, input().split()))
x = lst_n[n - 1]
left = []
right = []
i = -1
for j in range(0, n - 1):
    if lst_n[j] <= x:
        i += 1
        lst_n[i], lst_n[j] = lst_n[j], lst_n[i]
i += 1
lst_n[i], lst_n[n - 1] = lst_n[n - 1], lst_n[i]
ans = [
    "[" + str(lst_n[k]) + "]" if k == i else str(lst_n[k]) for k in range(len(lst_n))
]
print((" ".join(ans)))

def partition(lst, start, last):
    x = lst[last]
    i = start
    for j in range(start, last):
        if lst[j] <= x:
            lst[i], lst[j] = lst[j], lst[i]
            i += 1
    lst[i], lst[last] = lst[last], lst[i]
    return i


n = int(eval(input()))
n_lst = list(map(int, input().split()))
p = partition(n_lst, 0, n - 1)
str_lst = list(map(str, n_lst))
str_lst[p] = "[" + str_lst[p] + "]"
print((" ".join(str_lst)))

+def partition(lst, start, last): +    x = lst[last] +    i = start +    for j in range(start, last): +        if lst[j] <= x: +            lst[i], lst[j] = lst[j], lst[i] +            i += 1 +    lst[i], lst[last] = lst[last], lst[i] +    return i + + -lst_n = list(map(int, input().split())) -x = lst_n[n - 1] -left = [] -right = [] -i = -1 -for j in range(0, n - 1): -    if lst_n[j] <= x: -        i += 1 -        lst_n[i], lst_n[j] = lst_n[j], lst_n[i] -i += 1 -lst_n[i], lst_n[n - 1] = lst_n[n - 1], lst_n[i] -ans = [ -    "[" + str(lst_n[k]) + "]" if k == i else str(lst_n[k]) for k in range(len(lst_n)) -] -print((" ".join(ans))) +n_lst = list(map(int, input().split())) +p = partition(n_lst, 0, n - 1) +str_lst = list(map(str, n_lst)) +str_lst[p] = "[" + str_lst[p] + "]" +print((" ".join(str_lst)))