def partition(a)
  x = a.last
  left = []
  right = []
  a.each { |n| n < x ? left << n : right << n }
  result = left.join(' ') + " [#{x}] " + right.join(' ')
  result
end

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