def partition(a)
  x = a[-1][0]
  i = 0 # 前方に持ってくるためのindex
  0.upto(a.size - 1) do | j |
    if a[j].class == Array
      aj = a[j][0]
    else
      aj = a[j]
    end
    if aj <= x
      a[i], a[j] = a[j], a[i]
      i += 1
    end
  end
end

n = gets.to_i
a = gets.split.map(&:to_i)
a[-1] = [a[-1]]
partition(a)
ans = ''
a.each{ | b | ans = "#{ans}#{b} "}
puts ans.rstrip

