def partition(arr,p,r)
    x =arr[r]
    i = p-1
    j = p
    while j < r
        if arr[j] <= x
            i +=1
            arr[i],arr[j] = arr[j],arr[i]
        end
        j +=1
    end
    arr[i+1],arr[r] ="[#{arr[r]}]",arr[i+1]
    return i+1
end

n =gets.to_i
arr =gets.split(" ").map(&:to_i)
partition(arr,0,arr.count-1)
puts arr.join(" ")
