class Partion
  def solve
    n    = gets.chomp.to_i
    a = gets.scan(/\d+/).map(&:to_i)
    return partion(a, 0, n-1).join(" ")
  end

  def partion(a, p, r)
    x = a[r]
    i = p - 1
    (p...r).each do |j|
      if a[j] <= x
        i += 1
        a[i], a[j] = a[j], a[i]
      end
    end
    a[i+1], a[r] = "[#{a[r]}]" , a[i+1]
    return a
  end
end

if $0 == __FILE__
  puts Partion.new.solve
end