n = gets.to_i
a = gets.split.map(&:to_i)

class Array
  def partition
    r = pop
    a = select {|x| x <= r}
    b = select {|x| x > r}
    return a, b, r
  end
end

a1, a2, r = a.partition
puts a1.join(" ") + " [#{r}] " + a2.join(" ")
