#!/usr/bin/ruby
n=gets.to_i
a=gets.split.map(&:to_i)
x=a[a.length-1]
i=-1
0.step(a.length-2){|j|
	if a[j]<=x
		i=i+1
		a[i],a[j]=a[j],a[i]
	end
}
a[i+1],a[a.length-1]=a[a.length-1],a[i+1]
puts a.each_with_index.map{|e,z|(z==i+1?'[%d]':'%d')%e}*' '