n = gets.chomp.to_i
as = gets.chomp.split(' ').map(&:to_i)
r = as.last

j = -1
0.upto(n - 1) do |i|
  if as[i] <= r
    j += 1
    as[j], as[i] = as[i], as[j]
  end
end
as[j] = "[#{as[j]}]"
puts as.join(' ')
