def partition(p, r):

    x = A[r]

    i = p - 1

    for j in range(p, r):

        if A[j] <= x:

            i += 1

            A[i], A[j] = A[j], A[i]

    A[i + 1], A[r] = A[r], A[i + 1]

    return i + 1

n = int(eval(input()))

A = [int(i) for i in input().split()]

q = partition(0, n - 1)

A[q] = "[%d]"%A[q]

print((*A))
def partition(A, p, r):

    x = A[r]

    i = p - 1

    for j in range(p, r):

        if A[j] <= x:

            i += 1

            A[i], A[j] = A[j], A[i]

    A[i + 1], A[r] = A[r], A[i + 1]

    return i + 1

n = int(eval(input()))

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

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

A[p] = f"[{A[p]}]"

print((*A))

def partition(p, r):
    x = A[r]
    i = p - 1
    for j in range(p, r):
        if A[j] <= x:
            i += 1
            A[i], A[j] = A[j], A[i]
    A[i + 1], A[r] = A[r], A[i + 1]
    return i + 1


n = int(eval(input()))
A = [int(i) for i in input().split()]
q = partition(0, n - 1)
A[q] = "[%d]" % A[q]
print((*A))

def partition(A, p, r):
    x = A[r]
    i = p - 1
    for j in range(p, r):
        if A[j] <= x:
            i += 1
            A[i], A[j] = A[j], A[i]
    A[i + 1], A[r] = A[r], A[i + 1]
    return i + 1


n = int(eval(input()))
A = list(map(int, input().split()))
p = partition(A, 0, n - 1)
A[p] = f"[{A[p]}]"
print((*A))

-def partition(p, r): +def partition(A, p, r): -A = [int(i) for i in input().split()] -q = partition(0, n - 1) -A[q] = "[%d]" % A[q] +A = list(map(int, input().split())) +p = partition(A, 0, n - 1) +A[p] = f"[{A[p]}]"