 ns = []
 STDIN.each_line { |l| ns << l }
ns= ns.to_a.join.split[1..-1].map!(&:to_i)
 p = ns[-1]
 ns = ns[0..-2]

 a = []
 b = []
 ns.each { |d|
   if d <= p
     a << d
     b = b[1..-1] + [b[0]] if b.size != 0
     else
       b << d
     end}
b = b[1..-1] + [b[0]]

ret = a + ["[#{p}]"] + b
puts             ret