def partition(a, left, right)
  x = a[right]
  i = left-1
  left.upto(right-1) do |j|
    if a[j] <= x
      i += 1
      a[i], a[j] = a[j], a[i]
    end
  end
  a[i+1], a[right] = a[right], a[i+1]
  i+1
end

N = gets.to_i
A = gets.split.map(&:to_i)
q = partition(A, 0, N-1)
A[q] = "[#{A[q]}]"

puts A.join(" ")

