def partition(a)
  x = a.last
  r = a.size
  i = 0
  i.upto(r - 1) do |j|
    if a[j] <= x
      a[i], a[j] = a[j], a[i]
      i += 1
    end
    p a
  end
  a[0..i-2].join(' ') + " [#{a[i-1]}] " + a[i..-1].join(' ')
end

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